Hi,
I have a DGV with a data table as datasource.
One of the columns in the data table is a boolean column and is shown as a checkbox column at runtime.
I am trying to change the state of the checkbox depending on a condition.
When the checkbox is unchecked and the user clicks on it, a messagebox pops up asking if the user wants to mark it. This is a yesnocancel messagebox. The checkbox should be checked for both yes and no conditions and should remain unchecked for cancel.
If the checkbox is checked and the user clicks it then a yesno messagebox pop's up asking to uncheck it. It should get unchecked for 'yes' and remain checked for 'No'.
Here is the code that I am trying out, which does not work:
Code:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex != -1)
{
if (dataGridView1.CurrentCell == dataGridView1.Rows[e.RowIndex].Cells[0])
{
if ((bool)dataGridView1.Rows[e.RowIndex].Cells[0].Value == false)
{
DialogResult dr = MessageBox.Show("Delete the value?", "Delete", MessageBoxButtons.YesNoCancel);
dataGridView1.Rows[e.RowIndex].Cells[0].Value = (dr == DialogResult.Yes || dr == DialogResult.No) ? true : false;
}
else if ((bool)dataGridView1.CurrentCell.Value == true)
{
DialogResult dr = MessageBox.Show("Unmark the value?", "Delete", MessageBoxButtons.YesNo);
dataGridView1.Rows[e.RowIndex].Cells[0].Value = (dr == DialogResult.Yes) ? false :true ;
}
dataGridView1.ClearSelection();
}
}
}
I have been trying to make it work for quite some time now, with no results.
Any help would be greatly appreciated.