[英]Odd checkbox behavior in DataGridView with databinding
I am using databinding to bind List with my datagridview. 我正在使用数据绑定将List与我的datagridview绑定。
MyItem class contains checkbox element and displays correctly in datagridview. MyItem类包含复选框元素,并在datagridview中正确显示。 But the selection behavior is odd. 但是选择行为很奇怪。 When I select the check box the same field in MyItem does not update. 当我选中复选框时,MyItem中的相同字段不会更新。
When I change selected row(focus on checkedbox lost) the same field in corresponding instance of MyItem class is updated. 当我更改选定的行(失去选中框时)时,将更新MyItem类的相应实例中的相同字段。
If I understand you correctly, what you are describing is the standard behaviour for all DataGridView cell types - the cell value changed event (and the databinding) occurs when focus leaves the cell. 如果我理解正确,那么您所描述的是所有DataGridView单元格类型的标准行为-当焦点离开单元格时,发生单元格值更改事件 (和数据绑定)。
As they say in the article I linked to, and as you allude to in your question, for a checkbox this behaviour is often not ideal. 正如他们在我所链接的文章中所说,以及您在问题中提到的那样,对于此复选框,此行为通常不理想。 To work around this you can handle the CurrentCellDirtyStateChanged
and call the CommitEdit
method. 要解决此问题,您可以处理CurrentCellDirtyStateChanged
并调用CommitEdit
方法。 There is some discussion and example code here . 有一些讨论和示例代码在这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.