DataGridView CheckBox 列不会将更改应用于基础绑定对象

DataGridView CheckBox column doesn't apply changes to the underlying bound object

我有一个包含 Record 个对象的列表,这些对象在我的 DataGridView 中用作行。 每个 Record 都有一个新的 bool 值 Helped。果然,这个新值在我的表单中显示为复选标记。

就目前而言,选中此框时似乎不会更改相应 Record.

Helped bool 的值

我需要更改某种只读 属性 吗?如何将表单上的点击作为其 DataSource 值的变化传回?

编辑:我找到了 System.Windows.Forms.DataGridViewEditMode.EditOnEnter 属性,但我仍然没有看到我的 Record.Helped 属性 得到更新。

As it stands currently, when this box is checked it doesn't seem to change the value of Helped bool in the corresponding Record.

您对 DataGridView 的单元格所做的更改不会立即提交到数据源,直到您完成对单元格的编辑,然后更改才会被推送到数据源。如果出于任何原因你想尽快推送更改,你可以调用:

dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);

例如,您可以在 DataGridViewCellContentClick 事件中将复选框值推送到数据源的基础 属性。