Check box cell values are intended either for storage, like any other data, or for performing bulk operations.
If you want to respond immediately when users click a check box cell, you can handle the DataGridView.CellClick event, but this event occurs before the cell value is updated.
If you need the new value at the time of the click, one option is to calculate what the expected value will be based on the current value. Another approach is to commit the change immediately, and handle the DataGridView.CellValueChanged event to respond to it. To commit the change when the cell is clicked, you must handle the DataGridView.CurrentCellDirtyStateChanged event. In the handler, if the current cell is a check box cell, call the DataGridView.CommitEdit method and pass in the Commit value.
In DataGridView.CurrentCellDirtyStateChanged Event msdn document, it gives an example:
// This event handler manually raises the CellValueChanged event
// by calling the CommitEdit method.
void dataGridView1_CurrentCellDirtyStateChanged(object sender,
// If a check box cell is clicked, this event handler disables
// or enables the button in the same row as the clicked cell.
public void dataGridView1_CellValueChanged(object sender,
if (dataGridView1.Columns[e.ColumnIndex].Name == "CheckBoxes")
DataGridViewDisableButtonCell buttonCell =
DataGridViewCheckBoxCell checkCell =
buttonCell.Enabled = !(Boolean)checkCell.Value;
More information about datagridviewCheckboxCell: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcell.aspx
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
- Marked as answer by Jing0Moderator Friday, October 22, 2010 9:36 AM