private void DataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (DataGridView1.CurrentCell is DataGridViewCheckBoxCell) { if (DataGridView1.Columns[DataGridView1.CurrentCell.ColumnIndex].Name == "AvailableColumn") { DataGridView1.EndEdit(); bool Checked = Convert.ToBoolean(DataGridView1.CurrentCell.Value); } } }
private void DataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e) { // Workaround to fire CellValueChanged on a Checkbox change via mouse (left click) by switching cell focus if ((e.RowIndex < 0) || (e.ColumnIndex < 0)) { return; } if (DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].GetType().Name == "DataGridViewCheckBoxCell") { // Care with changing the following sequence as during lots of testing // this is the first and only combination that works in Windows and Mono.. om.DataUpdatePending = true; DataGridView1.EndEdit(); DataGridView1.ClearSelection(); om.DataUpdatePending = false; DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Selected = true; DataGridView1.Rows[e.RowIndex].Selected = true; } }
private void DataGridView1_KeyUp(object sender, KeyEventArgs e) { // Workaround to fire CellValueChanged on a Checkbox change via keyboard (space) by switching cell focus if (e.KeyCode == Keys.Space) { foreach (DataGridViewCell cell in DataGridView1.SelectedCells) { if (cell.GetType().Name == "DataGridViewCheckBoxCell") { DataGridViewCheckBoxCell SelectedCell = (DataGridViewCheckBoxCell)cell; e.Handled = true; // Care with changing the following sequence as during lots of testing // this is the first and only combination that works in Windows and Mono.. om.DataUpdatePending = true; SelectedCell.Value = !(SelectedCell.Value == null ? /*not set yet, so it's not checked*/ false : (bool)SelectedCell.Value); om.DataUpdatePending = false; DataGridView1.EndEdit(); DataGridView1.ClearSelection(); DataGridView1.Rows[SelectedCell.RowIndex].Cells[SelectedCell.ColumnIndex].Selected = true; } } } }