【发布时间】:2020-05-26 18:55:28
【问题描述】:
我知道以前有人问过类似的问题,但没有一个解决方案对我有帮助。
我在未绑定的 DataGridView 中有一个 DataGridViewCheckBoxColumn。
在CellContentClick事件中,当一个CheckBox被取消选中时,我根据DataGridView背后的业务规则提示用户是否要继续这个操作,如果他们选择不继续,我要重新勾选复选框。
这是对 CheckBox 的重新检查不起作用。
这是我的代码:
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;
}
}
}
}
正在设置单元格的值,但在视觉上未检查 CheckBox。
如果尝试了TrueValue 和FalseValue 的不同类型(布尔值与字符串),我尝试调用Refresh(),我尝试调用CommitEdit(),我尝试使用CheckState.Checked。
我可以做些什么来重新检查 CheckBox ?
【问题讨论】:
标签: c# winforms datagridview