ErrorProvider in Visual Basic .NET
Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013
This lesson describes the ErrorProvider control
This component indicates to the user that another control has an error associated with it. Basicaly, the ErrorProvider is an extender provider, as it adds a new Error property to the other controls on its form. For example, if the ErrorProvider is named MyErrorProvider, each control on the form gets a new property named "Error on MyErrorProvider." (you can use the Properties window to set or clear this value).
The ErrorProvider automatically displays a red circle containing an exclamation mark next to the control, and if the user hovers the mouse over the circle, the ErrorProvider displays a tooltip giving the error text.
You can also set it programmatically associating an error with a control at runtime. You should use the ErrorProvider's SetError method for that:
If Username.Text <> "admin" Then ErrorProvider1.SetError(Username, "Invalid username.") End IfTo remove an error at runtime, you use the same SetError method setting the error message to an empty string.
Note: you can change the default icon that the component displays for an error and use own error image instead. Previous Lesson | Next Lesson