ErrorWarnInfoProvider or any other ways to use RuleSeverity

ErrorWarnInfoProvider or any other ways to use RuleSeverity

Old forum URL: forums.lhotka.net/forums/t/7852.aspx


nlz242 posted on Thursday, October 22, 2009

Hi,

Im currently trying to implement the "RuleSeverity" concept in my application. The validations are working properly and returning "Warning" for some cases. However, im having a hard time getting it to display in any convinient/pleasant way in my UI.

My application currently uses ErrorProviders extensively and i am happy about it's behavior.

Now, im trying to get the same behavior for "Warnings" and "Informations" but i'm not having much success.
I have tried playing with "ErrorWarnInfoProvider" (2 or 3 versions on the contrib and in threads), however, the way my data are bound is not what ErrorWarnInfoProvider is expecting.

For exemple, i'm using Infragistic's ultragrid, the binding is done by setting the DataSource of the grid to a BindingSource object.
When ErrorWarnInfoProvider tries to build it's "control cache", it's only looking in the control's DataBindings collection and finds nothing.

I see, however, my Warning and Info list being populated by the GetWarnInfoList() method and it has everything i'm expecting (meaning my validations are working properly and they are even "found" by ErrorWarnInfoProvider.

After much messing around, ive decided to skip the part that searches in BindingSources and to simply look for my grid (Control is UltraGrid).
So now my "control cache" is filled. Good.
After that, "ProcessControl" looks in the "DataBindings" of my control (my UltraGrid) and finds nothing, therefor it does not call the provider's SetError.

Wanting to get this working as well as the ErrorProvider that is included in the framework, i went ahead and launched Reflector to see what's inside ErrorProvider. I found the way the "control finding" is done to be much more complex and i haven't had time to dig in and try to figure a way to implement it myself in ErrorWarnInfoProvider.

So right now im pretty much stuck... Either i try to copy Microsoft's code (which would be tedious and probably legally doubtful) or i find another way to display RuleSeverity...

Surely there is a simple way to do what im trying to do, and i missed it ? I mean... having a proper ErrorProvider implementation shouldn't be that hard, im surely missing something...

Any hints ? Tips ?

RockfordLhotka replied on Thursday, October 22, 2009

Sadly it really is that hard.

It isn't terribly hard to create an ErrorProvider replacement. But it can be very hard to alter the way datagrid controls work.

Windows Forms data binding comes in two flavors: simple and complex.

Simple binding is where a control binds a single property to the property of an object. So TextBox is an example.

Complex binding is where a control binds to the object as a whole. It is entirely up to the control how and what it does with the object, and usually the control's implementation is a black box. DataGrid, ListBox and other list-oriented controls work this way.

As you are aware, ErrorProvider only works with simple bound controls. Some datagrid controls replicate something like the ErrorProvider inside themselves - but it is really unique to each datagrid control.

If your datagrid control allows you to create custom column types (something that's common in WPF and Silverlight for example), then you can probably create a custom column type that displays a TextBox with an ErrorWarnInfoProvider in the cell. But I don't think most WinForms datagrid controls work that way?

JonnyBee replied on Friday, October 23, 2009

Hi,

The standard Microsoft DataGridView for Windows allows custom columns that are "unbound" when bound to a BindingSource - also called "Mixed Mode". This allows you to place a custom image and tooltip into a column to replicate and ErrorWarnInfoProvider.  I know C1 FlexGrid also allows the same and presumably the Infragistics grid.

For those interested in implementing this in the standard DatagridView I would recommend reading the DatagridView FAQ and accompanied samples.

The ErrorWarnInfoProvider is only designed for "Simple Binding" and will not work with grids.

Copyright (c) Marimer LLC