如何停止 DataGridView 调用 IDataErrorInfo.this[string columnName] get?
我有一个实现 IDataErrorInfo 的数据对象,但是验证逻辑有点慢。 不是那么慢,但足够慢,你不想多次调用它。 在我的应用程序中,这些对象的列表显示在 DataGridView 控件中。 网格是只读的,并且只包含有效的数据对象,但是 DataGridView 坚持为网格中的每个单元格调用 IDataErrorInfo.this[string columnName],这使得重绘非常慢。
我尝试将 ShowCellErrors 和 ShowRowErrors 设置为 false,但它仍然调用 IDataErrorInfo.this[string columnName]。 有什么想法可以阻止它验证我知道有效的对象吗?
I have a data object that implements IDataErrorInfo however the validation logic is a bit slow. Not that slow, but slow enough you don't want to call it a large number of times. In my application a list of these objects gets displayed in a DataGridView control. The grid is read-only and will only ever contain valid data objects, however the DataGridView is insisting on calling IDataErrorInfo.this[string columnName] for every cell in the grid which is making repainting very slow.
I have tried setting ShowCellErrors and ShowRowErrors to false, but it is still calling IDataErrorInfo.this[string columnName]. Any ideas how I stop it validating objects that I know are valid?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为一个便宜的选择...也许您可以在对象上设置一个标志,以禁用验证并始终从 2 个
IDataErrorInfo
方法返回""
?如果这是一个主要问题,您可以引入一个模仿实际类型但不实现 IDataErrorInfo 的传递对象。 要么通过手动编码外观,要么创造性地使用
System.ComponentModel
(大概是ITypedList
或TypeDescriptionProvider
;注意,它不会是仅对于单一类型就值得 - 手动编写类会更容易)。As a cheap option... perhaps a flag you can set on your object(s) that disables validation and always returns
""
from the 2IDataErrorInfo
methods?If it is a major problem you could introduce a pass-thru object that mimics the actual type but doesn't implement
IDataErrorInfo
. Either by manually coding a facade, or with some inventive use ofSystem.ComponentModel
(presumably anITypedList
orTypeDescriptionProvider
; note it wouldn't be worth it just for a single type - writing a class manually would be easier).