

/ Using the error provider control - several examples
#Vb net errorprovider example code
The code starts off with the default imports in addition to the defaults, the Regular Expression library has also been added to the code in order to support the evaluation of one of the text boxes against a regular expression. The application is very simple in execution, when the application is started, the form will display eight text box controls. Each of the controls has an event handler defined for the "Validated" event. Each control is validated against a different validation method so along with the "Validated" event handler a custom validation function has also been supplied. Each of these custom validation functions is used to evaluate the content of the associated text box and to display an indication adjacent to the control if that control fails the validation test. Minimal Length String (a string with at least three characters)įigure 3 (below) shows the solution explorer for the project. The project is entitled UseErrorProvider as can be seen in the figure, no additional references beyond the defaults were added to the project. The single form included is entitled "Form1".įigure 3: Solution Explorer with Both Projects Visible

#Vb net errorprovider example windows
There is a single solution contained in the demo project included with this download. This solution is a C# Windows Forms application that contains a single form. On the form are eight different text boxes and each these text boxes are validated against a different set of criteria: The example is used to validate the contents of some text box controls. Naturally it is just as easy to validate other controls such as a combo box control although it most likely going to be used with text box controls.

It is also possible to write a simple method to validate each of the fields in response to something like button click event. In the example provided, there is "Validate All" button that does test each of the controls on the form and mark any which contain invalid data. Normally one would write a custom validation method for each of the controls and test the control's content against that validation method whenever that specific control is validated. To use an error provider control, merely drop one from the toolbox onto the form you may use a single error provider control to mark any and all of the fields on a form, in this respect, using the error provider is similar to using the tool tip control. Once the control has been placed on the form, it may be controlled programmatically. This article shall address the use of the error provider control in Win Forms application development. The error provider control is most useful in displaying errors associated with data entry tasks on a Windows form. The error provider control is typically used to show errors related to data entry, however, the developer may also use it to display any desired icon and accompanying tool tip in response to any monitored event. For example, successful entries could be shown with a green checkmark as easily as failed entries could be shown with the standard red ball exclamation mark. (See figures 1 and 2 where both good and bad entries are marked using the error provider control).įigure 1: Error Provider Control in Use Marking Bad Inputįigure 2: Using the Error Provider to Show Non-Failure Related Information
