Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all

i m validating combobox for mandatory selection on submit click. so errorProvider displays error if user ll not select value . but after selecting value the error message still display on the form.. so pleas give me suggestion what should i have to do..
following is my code.
VB
Private Sub combo_Process_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles combo_Process.Validated
        ErrorProvider1.SetError(combo_Process, "")
    End Sub

    Private Sub combo_Process_Validating(ByVal sender As Object, ByVal e As  System.ComponentModel.CancelEventArgs) Handles combo_Process.Validating

        If combo_Process.SelectedIndex = 0 Then

            ErrorProvider1.SetError(combo_Process, "Precess selection required !!")
            e.Cancel = True


        End If
  End Sub
Posted
Updated 4-Jul-13 23:29pm
v4

From MSDN (http://msdn.microsoft.com/en-US/library/878fcck9(v=vs.90).aspx[^]):
"To clear the error message, call the SetError method and pass in Empty for the String value."
I.e. add an Else block like:
VB
Else
    ErrorProvider1.SetError(combo_Process, string.Empty)
 
Share this answer
 
v2
Quote:
If combo_Process.SelectedIndex = 0 Then

ErrorProvider1.SetError(combo_Process, "Precess selection required !!")
e.Cancel = True

End If

I think your validation condition is wrong.

Instead of:
If combo_Process.SelectedIndex = 0 Then
try:
If combo_Process.SelectedIndex = -1 Then

The items are zero indexed. An index of -1 indicates no selection has been made.

You may also want to correct the spelling mistake in the error message as well ("Precess" = "Process").
 
Share this answer
 
v2
Do This :

VB
'If No Error
    ErrorProvider1.Clear()
'End If
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900