Immediate Response from ErrorProvider?

Immediate Response from ErrorProvider?

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


SonOfPirate posted on Monday, November 19, 2007

One of the most frequent issues/questions that I have received lately from our testing group has to do with the default behavior of the Windows Forms ErrorProvider extender control.  No one seems satisfied any longer that they have to arrow, mouse or tab off of the control or press enter to get validation to occur and thereby get the error provider icon to display for invalid data.

For example, we have a numeric up/down control with min and max validation limits set to 0 and 10.  When the user increments up, they can continue past 10 endlessly with no feedback that a problem exists.  They tab off, mouse away, etc. and the error provider icon displays.  Our users would prefer to have the icon appear as soon as the value becomes invalid.

Does anyone have a suggestion how to accomplish this?

 

tmg4340 replied on Monday, November 19, 2007

OK... I guess I'll ask the obvious question...

If the min and max for validation are 0 and 10, why allow the spinner to go higher or lower?  Why not just restrict the control values?

I realize that doesn't really answer your question - I honestly am not sure what to tell you.  Since validation happens in the BO when the property values change, about the only option I see is to update the property values directly on your control Change events.  That surely defeats almost all of the purpose of data-binding, and - well, I'm sure you've already thought of three or four other bad things about this option.  But it probably would work.

McManus replied on Tuesday, November 20, 2007

My guess is that you use a DataSourceUpdateMode of OnValidation. If you change this to OnPropertyChanged, changed in the Control are immediately propagated to the BO.

You can set this value in the WinForms designer. Select the NumericUpDown control and then open the Advanced DataBindings property editor.

Hope this helps!

Cheers,
Herman

SonOfPirate replied on Tuesday, November 20, 2007

That certainly does do the trick!  We will have to be careful in using this setting, however, as there's quite a bit of activity under-the-hood as a result.  But, in the handful of cases where we'd like the immediate response, this will work great!  Thanks!

tmg4340, fyi...  We develop our UI's decoupled from the underlying business logic and min/max limits are components of the business logic.  So, the only way to physically limit the control is to expose properties containing these values from the business objects that we can bind the control's properties to.  While this is certainly possible, in our current case, the BO has 15 numeric properties and we were (& are) shying away from doing this.

And you're right, we haven't wanted to wire-up a Changed event handler to each control.  McManus' solution eliminates that need!

Thanks for the help.

 

Copyright (c) Marimer LLC