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
 

formlesstree4

Well-known member
Joined
Jul 17, 2008
Messages
61
Programming Experience
1-3
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
 

garyf

Member
Joined
Jul 4, 2007
Messages
5
Programming Experience
Beginner
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?
 

formlesstree4

Well-known member
Joined
Jul 17, 2008
Messages
61
Programming Experience
1-3
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
 

garyf

Member
Joined
Jul 4, 2007
Messages
5
Programming Experience
Beginner
Formlesstree4
You lost me there with your ref. to MYSQL/SQL. Not sure how your answer relates to my original question.
 

4461766964

Member
Joined
Sep 6, 2008
Messages
9
Location
North Idaho
Programming Experience
5-10
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.
 

garyf

Member
Joined
Jul 4, 2007
Messages
5
Programming Experience
Beginner
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
 
Top Bottom