CausesValidation and ControlBox

P

pa.singer

Developing a windows application with VB.Net under VS 2005. I am
wondering if anyone knows how I can prevent validation events from
firing if the user clicks on the control box close button to exit a
form. I do not want to set the CausesValidation property on all of the
form controls to False as I do want validation events to fire if the
user is tabbing from control to control. However, the control box
close button presents an apparently ugly issue because, when clicked,
not only does the validation event for the control being exited fire
but the FormClosing event still fires even if the validation event
fails and the program issues a Cancel. Has anyone else run across this
problem and found an elegant solution?

Thank you...
 
P

pa.singer

Well, the most "elegant" solution I've come up with so far is that the
cancel property of the FormClosingEventArgs is set to True at the start
of the event when a control just failed validation. So, I can check
that property and if it is set to True as soon as the event starts,
just skip any other code in the event. I would feel better about this
solution if I could trust Microsoft not to change this particular
behavior of CausesValidation to something that actually makes logical
sense in a future update or revision. If anyone thinks they have a
better solution, please let me know.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top