I am aware that similar questions have been asked before, but none of the solutions are helping me.
I have a DataGridViewCheckBoxColumn in an unbound DataGridView.
In the CellContentClick
event, when a CheckBox is unchecked, I am prompting the user whether they want to continue with this operation according to the business rules behind the DataGridView and, if they choose not to continue, I want to re-check the CheckBox.
It is this re-checking of the CheckBox that is not working.
Here is my code:
private void dgvPeriods_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == dgvPeriods.Columns["colSelected"].Index)
{
dgvPeriods.CommitEdit(DataGridViewDataErrorContexts.Commit);
DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)dgvPeriods[e.ColumnIndex, e.RowIndex];
if (chk.Value = chk.FalseValue)
{
If (MessageBox.Show("Continue with this Operation?", "Continue", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
chk.Value = chk.TrueValue;
return;
}
}
}
}
The value of the cell is being set, but visually the CheckBox is not checked.
If have tried different types for the TrueValue
and FalseValue
(booleans vs strings), I have tried calling Refresh()
, I have tried calling CommitEdit()
, I have tried using CheckState.Checked
.
What can I do to visually re-check the CheckBox ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…