tags:

views:

117

answers:

2

I have seen in certain places (sorry, am unable to provide links at the moment) that validation errors in a form are displayed in a label at the top. As the user fills up the form, that error text changes accordingly.

I can see an obvious if...else and handling "Validating" etc events to implement this (though it can turn out to be very tedious for complex forms). Is there a more straightforward, cleaner way to do this?

Thanks!

A: 

If you want to avoid adding "Validating" events to all your textboxes on the form (and with this making complex forms even more complex) maybe you should try catching all input via the OnKeyDown event of the form and make some parsing there (keeping track of what was written and what object has focus). This way you handle everything in one place.

Ezekiel Rage
+1  A: 

You should look into implementing IDataErrorInfo as described in this blog post. You can then bind your Label to the IDataErrorInfo.Error property. Add a little INotifyPropertyChanged and your Label will update auto-magically.

Julien Poulin