validating an entire form  
Author Message
Andrew Shearer





PostPosted: Visual Basic Express Edition, validating an entire form Top

i have errorproviders on my form to ensure fields are valid, but im wondering what the best way is to check this on the OnClick button event

at the moment im using this logic:-

If epError.GetError(txtCode) = "" Then

Me.DialogResult = System.Windows.Forms.DialogResult.OK

Me.Close()

End If

shouldn't the epError control have a boolean property to tell me whether [any] controls that have been assigned to it are still invalid



Visual Studio Express Editions43  
 
 
Peter Ritchie





PostPosted: Visual Basic Express Edition, validating an entire form Top

ErrorProvider is really just a presentation mechanism for you own internal error checking/validation logic. If you wan to tell if ErrorProvider has an error for a given Control, you can use the GetError method and String.IsNullOrEmpty().

 
 
Moayad Mardini





PostPosted: Visual Basic Express Edition, validating an entire form Top

You must validate the user input using your own code then use that control to show the error to the user, that control can not be use as a validation control.
HTH


 
 
Andrew Shearer





PostPosted: Visual Basic Express Edition, validating an entire form Top

thanks for the responses.
i realise that i have to write my own code, but it would seem logical to me that validating an entire form would relate to the errorprovider(s) i have on the form

so is there a 'validation' control how are other people doing this at the moment my form validation ( on my save button click event) consists of ensuring that all of my errorprovider(s) do not have an error message set....


 
 
Moayad Mardini





PostPosted: Visual Basic Express Edition, validating an entire form Top

There are some functions to validate some things, but what is the validation which you want to do

 
 
mhutter





PostPosted: Visual Basic Express Edition, validating an entire form Top

To find out if the entire form is valid on a click event, call the Form.ValidateChildren method. This will fire the Validating event for all children controls on the form. You then handle the Validating event for each control you want to check on the form and set the e.cancel = true if one of those fields does not meet your requirements.