DataGridView CheckBox 列不会将更改应用于底层绑定对象 [英] DataGridView CheckBox column doesn't apply changes to the underlying bound object

查看:11
本文介绍了DataGridView CheckBox 列不会将更改应用于底层绑定对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Record 对象列表,它们在我的 DataGridView 中用作行.每个Record 都有一个新的布尔值Helped.果然,这个新值在我的表单中显示为复选标记.

I have a list of Record objects that serve as rows in my DataGridView. Each Record has a new bool value Helped. Sure enough, this new value shows up as check mark in my form.

当时,当检查此框时,似乎似乎更改了相应记录中的帮助 bool的值.

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

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

Is there some sort of read-only property I need to change? How do I pass a click on my form back as a change in value of its DataSource?

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

I've found the System.Windows.Forms.DataGridViewEditMode.EditOnEnter property, but I'm still not seeing my Record.Helped property get updated.

推荐答案

目前,当检查此框时,它似乎没有修改对应Record中Helped bool的值.

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 的单元格所做的更改,在您完成编辑单元格之前不会立即提交到数据源,然后更改将被推送到数据源.如果出于任何原因您想更快地推送更改,您可以调用:

The changes which you make on a cell of DataGridView, doesn't commit immediately to the data source until you finish editing the cell, then changes will be pushed to data source. If for any reason you want to push changes sooner, you can call:

dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);

例如,您可以在 DataGridViewCellContentClick 事件中执行此操作,将复选框值推送到数据源的基础属性.

For example you can do that in CellContentClick event of your DataGridView to push check box value to the underlying property of data source.

这篇关于DataGridView CheckBox 列不会将更改应用于底层绑定对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆