How to stop DataGridView when calling IDataErrorInfo.this [string columnName] get?

I have a data object that implements IDataErrorInfo, however the validation logic is a bit slow. Not so slow, but slow enough, you don’t want to call him many times. In my application, a list of these objects is displayed in the DataGridView control. The grid is read-only and will only contain valid data objects, however the DataGridView insists on calling IDataErrorInfo.this [string columnName] for each cell in the grid, which makes the redraw very slow.

I tried setting ShowCellErrors and ShowRowErrors to false, but it still calls IDataErrorInfo.this [string columnName]. Any ideas how I can stop it by checking objects that I know are valid?

+3
source share
1 answer

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

obj.ValidationEnabled = false; // etc

If this is a serious problem, you can introduce a pass-thru object that mimics the actual type but does not implement it IDataErrorInfo. Either by manually encoding the facade, or by using some inventive use System.ComponentModel(presumably, ITypedListor TypeDescriptionProvider; note that this would not be worth it for just one type - writing a class manually would be easier).

+1
source

Source: https://habr.com/ru/post/1712088/


All Articles