views:

276

answers:

1

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?

+1  A: 

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

Marc Gravell
I had considered that, but was hoping there was an easier way.
Martin Brown