I am working on a DataGridView
called ListingGrid
trying to activate / deactivate users that have been "checked" on any DataGridViewCheckBoxCell
that is inside the DataGridViewCheckBoxColumn
.
This is the way im trying to do that :
foreach (DataGridViewRow roow in ListingGrid.Rows)
{
if ((bool)roow.Cells[0].Value == true)
{
if (ListingGrid[3, roow.Index].Value.ToString() == "True")
{
aStudent = new Student();
aStudent.UserName = ListingGrid.Rows[roow.Index].Cells[2].Value.ToString();
aStudent.State = true;
studentList.Add(aStudent);
}
}
}
As far as I get, when you check a DataGridViewCheckBoxCell
, the value of the cell is true
right? But it is not allowing me to convert the value to bool and then compare it, throwing me an invalid cast exception.