具有CheckBox单元格问题的DataGridView

我有一个带有DataGridViewCheckBoxColumn列的DataGridView,它被数据绑定到一个列表。 问题是,此复选框的数据绑定布尔属性不会在选中/取消选中复选框时更新,而是在CellLeave事件之后,换句话说在单元格失去焦点之后更新。 我希望在检查/取消选中后立即更新此属性。 有一个事件CurrentCellDirtyStateChanged在检查/取消选中后立即触发,因此我可以使用它来手动更新该属性。 有一个更好的方法吗?

您可以侦听CurrentCellDirtyStateChanged事件并强制提交更改:

void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (dataGridView1.IsCurrentCellDirty) { dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit); } }