如何停止 DataGridView 调用 IDataErrorInfo.this[string columnName] get?

发布于 2024-07-25 23:32:19 字数 338 浏览 2 评论 0原文

我有一个实现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吹梦到西洲 2024-08-01 23:32:19

作为一个便宜的选择...也许您可以在对象上设置一个标志,以禁用验证并始终从 2 个 IDataErrorInfo 方法返回 ""

obj.ValidationEnabled = false; // etc

如果这是一个主要问题,您可以引入一个模仿实际类型但不实现 IDataErrorInfo 的传递对象。 要么通过手动编码外观,要么创造性地使用 System.ComponentModel(大概是 ITypedListTypeDescriptionProvider;注意,它不会是仅对于单一类型就值得 - 手动编写类会更容易)。

As a cheap option... perhaps a flag you can set on your object(s) that disables validation and always returns "" from the 2 IDataErrorInfo methods?

obj.ValidationEnabled = false; // etc

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 of System.ComponentModel (presumably an ITypedList or TypeDescriptionProvider; note it wouldn't be worth it just for a single type - writing a class manually would be easier).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文