I have a dataGridView with Sql Data Source. Columns name are (Program_code) and (UserNo) in table (Priviliges). I want to check if the row have (Program_code) to the user that I selected if its in, the checkbox in dataGridViwe in the same column with (program_name) is checked for all the column ... i make the code but only one row is checked i will give pictuer for you to understand if the user have permission the checked
private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
SqlDataAdapter UserSearch = new SqlDataAdapter("SELECT Program_Name FROM Programs ORDER BY Program_Name ASC ", conn);
var datast = new DataSet();
UserSearch.Fill(datast);
dataGridView1.ReadOnly = true;
dataGridView1.DataSource = datast.Tables[0];
dataGridView1.Columns[0].Width = 25;
dataGridView1.Columns[1].Width = 355;
}
//callData to DataGridEnd
//SortingData to DataGridStart
catch (Exception t)
{
MessageBox.Show(t.Message);
}
SqlDataAdapter UserNo = new SqlDataAdapter("SELECT UserNo FROM Users WHERE UserName= N'" + comboBox1.SelectedItem.ToString() + "'", conn);
DataSet UserNOO = new DataSet();
UserNo.Fill(UserNOO);
label1.Text = UserNOO.Tables[0].Rows[0][0].ToString();
SqlDataAdapter Program_Code = new SqlDataAdapter("SELECT Program_Code FROM Priviliges WHERE UserNo= N'" + UserNOO.Tables[0].Rows[0][0].ToString() + "'", conn);
DataTable Program_Codee = new DataTable();
Program_Code.Fill(Program_Codee);
try
{
{
foreach (DataRow row in Program_Codee.Rows)
{
no = row["Program_Code"].ToString();
}
}
DataRow[] foundAuthors = Program_Codee.Select("Program_Code = '"+no+"'");
if (foundAuthors.Length != 0)
{
label2.Text = foundAuthors[0][0].ToString();
SqlDataAdapter ProgName = new SqlDataAdapter("SELECT Program_Name FROM Programs WHERE Program_Code = N'" + foundAuthors[0][0].ToString() + "' ORDER BY Program_Name ASC ", conn);
DataTable rowIndexx = new DataTable();
ProgName.Fill(rowIndexx);
label3.Text = rowIndexx.Rows[0][0].ToString();
int rowIndex = -1;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Cells[1].Value.ToString().Equals(rowIndexx.Rows[0][0].ToString()))
{
rowIndex = row.Index;
label4.Text = rowIndex.ToString();
dataGridView1.Rows[rowIndex].Cells["n"].Value = true;
}
}
}
catch (Exception t)
{
MessageBox.Show(t.Message);
}
//callData to DataGridStart
}
Aucun commentaire:
Enregistrer un commentaire