how to hide the error provider icon after displaying the error mesaage?

rajesh.forum

Well-known member
Joined
Sep 7, 2007
Messages
55
Programming Experience
Beginner
this s the sample code i ve using..but here i need to hide the error provider
if i select any other item other than "::select::"

Private Sub cbDesignation_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cbDesignation.Validating
Dim err As New ErrorProvider
If Me.cbDesignation.Text = "::Select::" Then
err.SetError(cbDesignation, "Field is Required")
ElseIf Me.cbDesignation.Text <> "::Select::" Then
err.SetError(cbDesignation, "")
End If
End Sub
 
put

VB.NET:
err.SetError(cbDesignation, "")

after the IF statment

VB.NET:
If Me.cbDesignation.Text = "::Select::" Then
err.SetError(cbDesignation, "Field is Required")
End If

err.SetError(cbDesignation, "")

Hope it helps ;)
 
your using a combobox right? Why not make the "DropDownStyle" to "DropDownList" considering that the user will not enter tect inside the combobox but just choose it

Then you can just use the error provider if nothing was chosen from the combobox - or make a default value that the user "will" use a value ay time
 
this worked

VB.NET:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If ComboBox1.Text = "::Select::" Then
            ErrorProvider1.SetError(ComboBox1, "Error")
            Exit Sub
        End If
        ErrorProvider1.SetError(ComboBox1, "")
End Sub
 
i need to validate when i press the tab key..so im using this event ...i no need in btn_click event ...can u help me in this or any similar event like this..

Private Sub cbDesignation_Validating[/B](ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cbDesignation.Validating Dim err As New ErrorProvider
If Me.cbDesignation.Text = "::Select::" Then
err.SetError(cbDesignation, "Field is Required")
e.Cancel = True
Return
Exit Sub
End If
err.SetError(cbDesignation, "")
End Sub
 
try putting it in this event - since your handling text changing

VB.NET:
Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged
        If ComboBox1.Text = "::Select::" Then
            ErrorProvider1.SetError(ComboBox1, "Error")
            Exit Sub
        End If
        ErrorProvider1.SetError(ComboBox1, "")
End Sub
 
The problem is you create a new ErrorProvider component and set for the control for each validation. Use only one ErrorProvider component (or at least reset the same component you did set before). You can add one to the form from Toolbox (components), it's default name will be "ErrorProvider1". This component you can configure and use to set error text for several controls to be validated. Now when you remove the error the icon will also disappear. By adding a ErrorProvider component to the form you will now also get a new property in designer for all controls "Error on ErrorProvider1" where you can type the error text.
 
Back
Top