只读 DataGridView 和 IEditableObject
晚上好,
我在 .NET Windows 窗体项目中的 DataGridView 遇到了一个小问题。 该网格是只读的,并绑定到包含自定义业务对象的可排序 BindingList
。 我的业务对象类确实实现了 IEditableObject。
现在,在网格中导航时始终会调用 BeginEdit
和 EndEdit
方法。 有没有办法阻止网格或绑定源这样做? 它被显式设置为只读(ReadOnly = true),因此根本没有理由(不,我们仔细地说我没有看到任何理由)一遍又一遍地调用这些方法。
感谢您的阅读:)
马蒂亚斯
Good evening
I've got a little problem with my DataGridView in a .NET Windows Forms project. The grid is read-only and bound to a sortable BindingList<T>
which contains custom business objects. My business object class does implement IEditableObject
.
Now the BeginEdit
and EndEdit
methods are called all the time while navigating in the grid. Is there a way to prevent the grid or binding source from doing this? It is explicitly set to read only (ReadOnly = true), so there's no reason at all (no, let's carefully say that I see none) to call these methods over and over.
Thank you for reading :)
Matthias
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
复制您的问题后,DataGridView 似乎调用了一系列方法/事件,无论发生什么,这些方法/事件最终都会调用您的 IEditableObject 事件...
当您将 BindingList 设置为 DataGridView.DataSource 以及在网格中导航时,就会发生这种情况。
无论我为 DataGridView 选择哪种 EditMode,代码都将进入 BusinessObjects 的 IEditableObject.EndEdit() 方法。
看来这是框架的一个旧BUG...我发现了这个错误报告。
这个错误报告很旧了。 我不确定这是否仍然是一个问题......也许已经有一些属性可以解决这个问题。
有什么想法吗?
After replicating your problem it seems the DataGridView calls a chain of methods/events that end up with calling your IEditableObject event no matter what ...
This happens when you set your BindingList to the DataGridView.DataSource, and when you navigate through the Grid.
Regardless of the EditMode I select for the DataGridView, the code will step into the IEditableObject.EndEdit() method of the BusinessObjects.
It seems this is an old BUG of the framework...I found this Bug Report.
This bug report is very old. I'm not 100% sure if this is still an issue ... maybe there is already some property to solve this.
Any thoughts?