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

*爱你&永不变心* 提交于 2019-11-26 23:42:43

问题


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.

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

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?

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


回答1:


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

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);

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



来源:https://stackoverflow.com/questions/40347686/datagridview-checkbox-column-doesnt-apply-changes-to-the-underlying-bound-objec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!