I am working in c# windows application populate record from sql server to data grid view, with dynamic checkbox facility in each row. i want to select selected rows for some purpose via checkbox of that particular row. till now i successfully achieve my target. but i'm facing a minor issue regarding saving a checked status, Example i want to check only those records whose Name = Max i have a textbox in that textbox i call text chnage event with like Query
Code for Filter by name:
try
{
SqlCommand cmd = null;
SqlConnection con = null; Ranks rank = new Ranks();
con = new SqlConnection(cs.DBcon);
con.Open();
cmd = con.CreateCommand();
cmd.CommandText = "Select * from Records where Name like @Name order by Pno";
cmd.Parameters.AddWithValue("@Name", "%" + FilterByNameTextbox.Text.Trim() + "%");
SqlDataAdapter adapter1 = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter1.Fill(dt);
dataGridView1.DataSource = dt;
Make_fields_Colorful();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
if i write Max in filter by name textbox it would return 3 records with name starts with max using like query as i mention code above. so i only check 2 records out of 3 using dynamic checkbox, till now my code runs perfectly. Now i want to check records which name starts from Ali, now when i write ali in my filter by name textbox it will return rows where name like ali , but problem comes here it will remove my previous checked records, so how i would able to save checked records for both max and ali's rows:
Code for adding dynamic checkboxes in each row
DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.Name = "checkBoxColumn";
checkBoxColumn.DataPropertyName = "Report";
checkBoxColumn.HeaderText = "Report";
dataGridView1.Columns.Insert(10, checkBoxColumn);
dataGridView1.RowTemplate.Height = 100;
dataGridView1.Columns[10].Width = 50;
Please suggest me with your code , i would like to appreciate your quick response.
Thanks in advance
Aucun commentaire:
Enregistrer un commentaire