I have found several related articles and tried them, but couldn't solve the problem. I have a checkbox column in the datagridview of my winForm application. I want to select multiple rows by checking the checkboxes of the adjacant rows and perform some operation on selected rows. But my rows are not getting selected. My code is:
this.dgvLoadTable.CellClick += new DataGridViewCellEventHandler(dgvLoadTable_CellClick);
private void dgvLoadTable_CellClick(object sender, EventArgs e)
{
foreach (DataGridViewRow row in dgvLoadTable.Rows)
{
//If checked then highlight row
if (Convert.ToBoolean(row.Cells["Select"].Value))// Select is the name
//of chkbox column
{
row.Selected = true;
row.DefaultCellStyle.SelectionBackColor = Color.LightSlateGray;
}
else
row.Selected = false;
}
}
What I'm doing wrong here?
CellContentClickorCellValueChanged(given that you make sure you're clicking on theSelectcell) events. That will make sure you actually click the checkbox and not the surrounding area of the checkbox. Did you try and debug to see if it actually goes into the foreach loop?