Call to Validate

garyf

Member
Joined
Jul 4, 2007
Messages
5
Programming Experience
Beginner
Hi all

I've seen lots of snippets in the Save Method of the BindingNavigator control that contains just:

Validate()
datatable.EndEdit
datatable.Update

In my winforms app, I did a debug on the call to the Validate() and found it fired the validating event of just one control on the form, not all of them.

1. shouldn't it fire the validating events on all controls on the form?
2. how do you get it to fire the validating events on all controls on the form?
2. how to you prevent execution from going to the datatable.EndEdit statement when an error is found in the validating event?

TIA
 
1. shouldn't it fire the validating events on all controls on the form?
2. how do you get it to fire the validating events on all controls on the form?
2. how to you prevent execution from going to the datatable.EndEdit statement when an error is found in the validating event?

1. If the validation events are same names, then yes.
2. Use the same format, just with the name of the validating event.
3. No clue...reword that for me...little sleep kills the mind
 
thank you for your response and my apologies for not getting back to you sooner.
>3. No clue...reword that for me...little sleep kills the mind
After the call to Validate()
shouldn't there be a check to see the results of the validation and prevent further execution (ie the calls to datatable.EndEdit and datatable.Update) if validation failed?
 
In MySQL and SQL, if the statement is wrong, then it won't go through...i think that's what you mean. I'm not sure...lol
 
Formlesstree4
You lost me there with your ref. to MYSQL/SQL. Not sure how your answer relates to my original question.
 
I'm not sure why the wizard puts the Validate() code in for the save button. However, if I understand your question, you'd want to validate your controls as the user enters the information, not just before the save. When a control has it's "causes validation" property set to true, it fires its own validation as the user leaves that control. This is where and when you would want to validate, throw an error if necessary and request a correction immediately. That way the user would not need to go back and correct problems later as they try to save. There are lots of control validation examples/snippets available out there. I like the examples that automatically re-select the invalid information for correction.
 
4461766964,

Thank you for your response. I guess I can just delete that call to Validdate then. I normally do the validation as you have described.

Cheers
 
Back
Top