ErrorProvider

Few days ago I worked on some winforms and needed some validator controls. I thought that the winforms should have the same validator controls as webforms. However I could not find them. So I used the ErrorProvider control which also does a good job. However it does not come with any regular expressions or something like that to validate any email or web url. You will have to find the regular expression on your own. A good website to to do that is RegExLib. This Website already contains many pre-defined regular expressions. It also contains basics to learn regular expressions. Let's get back to the ErrorProvider. To implement the ErrorProvider in your project, just drop it in your form or double click it and you will see it below the form in a bar. Now each control on your form will get an extra property called: Error on ErrorProvider1. You can set the default error message here if you want. If not you can leave it blank and in your code you can access the property via the method SetError. Just define the message in the SetError method and it works. If an error occurs you won't get any MessageBox or the errormessage isn't displayed under the control. Instead you will see a small icon right from the control which will blink for a few times. If you then hover over the control, you will see the errormessage as a tooltip. Something like this:



You can even use your own icons for that.

Update: I just had a short IM conversation with Christian Weyer and he told me that there aren't any validator controls for win forms. One way would be to use the Validating event, but that's old school style and he hopes and actually thinks they will be there in 2.0. Microsoft don't disappoint me and Chris :-)

Sonu

Comments

# David Silverlight said:

Yes, I agree that it is better to display the error message on the form so that the user can see it directly. Although it is nice the way that it displays it as a tooltip when you hover over the exclamation point, that should be in addition to displaying in behavior. Unfortunately, I do not work very much with winforms, so the only suggestion that I would have would be on the manual variety. It would be nice to find out if there is a built in mechanism similar to the validation control implementation. I will check this post later in case any good suggestions are posted.

Wednesday, July 14, 2004 8:54 AM
# Phil Weber said:

Sonu: You may find this article (and the others in the series) interesting:
http://msdn.microsoft.com/library/en-us/dnforms/html/winforms05182004.asp

Wednesday, July 14, 2004 10:31 AM
# Sonu Kapoor said:

Thanks for the URL's Phil! The articles are indeed interesting.

Wednesday, July 14, 2004 10:54 AM
# Nish said:

Interesting write-up, Sonu.

Wednesday, July 14, 2004 10:52 PM
# Sonu Kapoor said:

Thanks Nish!

Thursday, July 15, 2004 7:10 AM

Leave a Comment

(required) 
(required) 
(optional)
(required)