I was unable to count checked checkboxes in DataGridView. I want to count the checked checkboxes during the checkbox is checked and store the number of checked items in a label. I tried the following code but does not give the correct count:
int num = 0;
private void dgvLoadData_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
bool isChecked = Convert.ToBoolean(dgvLoadData.Rows[dgvLoadData.CurrentCell.RowIndex].Cells[0].Value.ToString());
if (isChecked)
{
num+=1;
}
else
{
num-=1;
}
labelSelectedSum.Text = "Selected Items: " + num;
}