I have a datagridview with a checkbox clomunn. When checkbox is checked/unchecked the messagebox appears with question "Do you really want to change a value?" If Yes is clicked the checkbox value set to a new value. If No button is clicked the
checkbox value return to old value.
How can i do that ? This is my code but it doesn't work. When I clikced No button the value return, but when current cell losts focus the value is changed again to a new value.
private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (dataGridView1.IsCurrentCellDirty) { dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit); } } private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Rows.Count == 0) return; if (e.ColumnIndex == dataGridView1.Columns["checkboxcol"].Index) { DataGridViewCheckBoxCell dgvc = (DataGridViewCheckBoxCell)dataGridView1.Rows[e.RowIndex].Cells["checkboxcol"]; DialogResult mbDr = MessageBox.Show("Question","AppName", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (mbDr == System.Windows.Forms.DialogResult.No) { dataGridView1.CancelEdit(); } } }