I've looked at other posts regarding this but i cant seem to get a value out of a DataGridViewCheckBoxCell
besides an empty string.
Here is what I've tried to set the true and false values of the cell upon instancing a new row but to no avail. I'm creating all the columns and rows at runtime btw so the editor doesn't apply.
//Default checkBox true and false values are the same and must be set to true and false
if (Program.mainForm.TableMainGridView.Columns[column.Name] is DataGridViewCheckBoxColumn)
{
val = false;
DataGridViewCheckBoxCell cell = new DataGridViewCheckBoxCell();
cell.FalseValue = false;
cell.TrueValue = true;
Program.mainForm.TableMainGridView.Rows[index].Cells[column.Name] = cell;
}
I then tried the solution to this question by casting the cell as a DataGridViewCheckBoxCell
before retreiving it's value upon the CellContentClick
event (with and without me trying to set the cell.FalseValue
& cell.TrueValue
) and also to no avail.
DataGridViewCheckBoxCell cell = Program.mainForm.TableMainGridView.Rows[e.RowIndex].Cells[e.ColumnIndex] as DataGridViewCheckBoxCell;
if (Convert.ToBoolean(cell.Value) == true)
{
value = true;
}
else
{
value = false;
}
I also saw that there was a way to set the true and false values of the column itself which would be ideal if it does in fact set the values of all subsequent cells but that doesn't seem to do anything either.
Does anyone else have this issue with creating a DataGridViewCheckBoxColumn
and row in script then being able to get a value out of the checkbox cell?