Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you stop DataGridView calling IDataErrorInfo.this[string columnName] get?

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?

like image 838
Martin Brown Avatar asked Jun 06 '26 08:06

Martin Brown


1 Answers

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).

like image 171
Marc Gravell Avatar answered Jun 07 '26 21:06

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!