private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
var cell= dataGridView1.CurrentCell;
if (dataGridView1.IsCurrentCellDirty)
{
if (dataGridView1.Columns[cell.ColumnIndex].Name == "Active" && cell.RowIndex >= 0)
{
bool isChecked = (bool)(dataGridView1.Rows[cell.RowIndex].Cells[0].Value);
if (!isChecked)
{
if (activate(cell.RowIndex))
{
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
else
{
dataGridView1.CancelEdit();
}
}
else
{
deactivate(cell.RowIndex);
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}