I want to get a checkbox value from a datagridview(True/False) but I always get a value "null", here is the code where i get the value of the checkbox:
DataGridViewCheckBoxCell boolean = (DataGridViewCheckBoxCell)dgv[e.ColumnIndex, e.RowIndex];
string checkCheckboxChecked = ((bool)boolean.FormattedValue) ? "False" : "True";
This code returns a false
in the Boolean.FormattedValue
even the checkbox is checked
and also I tried another:
object value = dgvVisual[e.ColumnIndex, e.RowIndex].Value;
And this code return a value of null
Why does this happen?
P.S. e
is an event of the CELL CONTENT CLICK
.
Here is the full code of the datagridview cell content click:
private void dgvVisual_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int Number1= int.Parse(dgvVisual[0, e.RowIndex].Value.ToString());
int Number2 = (e.ColumnIndex - 1);
DataGridViewCheckBoxCell boolean = (DataGridViewCheckBoxCell)dgvVisual[e.ColumnIndex, e.RowIndex];
bool checkCheckboxChecked = (null != boolean && null != boolean.Value && true == (bool)boolean.Value);
//string checkCheckboxChecked = "";
if (checkCheckboxChecked)
{
//do something if the checkbox is checked
}
else
{
//do something if the checkbox isn't
}
}
SOLVED:
I changed the CELL END EDIT EVENT
and add the click content to datagridview.CurrentCell
to another cell.