private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
// Column 0 is the Checkbox column that I need.
if (e.ColumnIndex == 0)
{
// This gets the Checkbox cell.
DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)fileGrid.Rows[e.RowIndex].Cells[0];
// Always displays True.
MessageBox.Show((cell.Value == null) + "");
}
}DataGridView checkboxes
I've tried for about an hour now just to figure out if a checkbox in a DataGridView control is checked or not. The Value field is always null, whether checked or not, and there is no Checked field like a Checkbox has. How can I detect if a cell is checked or not?
PaulPosted Jun 14, 2007, 8:09 PM
if (cell.EditedFormattedValue.Equals (true)) { // The cell is checked. }I don't understand the difference, but oh well, it works.