articles

ErrorProvider Control in VB.Net

Pushpendra Singh32317 12-Dec-2010

ErrorProvider allows us to set an error message for any control on the form when the input is not valid. When an error message is set, an icon indicating the error will appear next to the control and the error message is displayed as Tool Tip when the mouse is over the control.

Drag and drop ErrorProvider and TextBox  control from toolbox on the window Form.

ErrorProvider Control in VB.Net

ErrorProvider Control in VB.Net

Drag and drop a Button.

ErrorProvider Control in VB.Net

Code:

 

     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Then ' condition is given so that empty textbox could not save
ErrorProvider1.SetError(TextBox1, "Cannot leave textbox blank")'error text will show as tooltip
 
        Else
            ErrorProvider1.SetError(TextBox1, "")
        End If
 
    End Sub
End Class

Run the project

ErrorProvider Control in VB.Net

If textbox is empty and Submit button is clicked then error icon will display.

ErrorProvider Control in VB.Net

When any value (text or number) is entered in textbox and Submit button clicked then form will execute.

ErrorProvider Property:

Icon property:   which allows us to set an icon that will be display when error occurred?

 BlinkRate property:   which allows setting the rate in milliseconds at which the icon blinks.

Icon:    Gets or sets the Icon that is displayed next to a control when an error occurred. 

BlinkStyle:   Gets or sets a value indicating when the error icon flashes. 


Updated 18-Apr-2020

Leave Comment

Comments

Liked By