我有一个 Record
的列表在我的 DataGridView 中充当行的对象。
每个Record
有一个新的 bool 值 Helped
.果然,这个新值在我的表单中显示为复选标记。
就目前而言,选中此框后似乎不会更改 Helped
的值bool中对应Record
.
是否需要更改某种只读属性?如何将表单上的点击作为其 DataSource
值的变化传回?
编辑:我找到了 System.Windows.Forms.DataGridViewEditMode.EditOnEnter
属性(property),但我仍然没有看到我的 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);
例如,您可以在 DataGridView
的 CellContentClick
事件中执行此操作,以将复选框值推送到数据源的基础属性。
关于c# - DataGridView CheckBox 列不会将更改应用于基础绑定(bind)对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40347686/