0
votes

I have DataGridView in windows form which contains 13 checkboxes. one checbox i-e(the first one) is to check all other checkboxes which are basically for months. So now I want that when I check the first checkbox all of the other checkboxes should be checked and when I uncheck the first checkbox all checkboxes should be unchecked. My code works correct when I check the first checkbox but when I uncheck the first checkbox still all checkboxes are checked. but I want them to be unchecked. I have used CellContentClick event.
Here is my code.

if (e.ColumnIndex == 1)
{
    for (int k = 2; k <= 13; k++)
    {
        DataGridViewCell cell = dataGridView1.Rows[e.RowIndex].Cells[k];
        DataGridViewCheckBoxCell checkCell = cell as DataGridViewCheckBoxCell;
        checkCell.Value = true;
    }
}
1

1 Answers

0
votes

Value return an object type and that cannot be compared to a boolean value. You can cast the value to bool

 if ((bool)row.Cells[1].Value == true)
        {
            // what I want to do
        }

try this :

 foreach (GridViewRow gvrow in gvDetails.Rows)
        {
            CheckBox chk = (CheckBox)gvrow.FindControl("chkSelect");
            if (chk != null & chk.Checked)
            {
                str += gvDetails.DataKeys[gvrow.RowIndex].Value.ToString() + ',';
                strname += gvrow.Cells[2].Text + ',';
            }
        }