Form Closing fires textbox Validation and aborts close

  • Thread starter Thread starter Erik Jensen
  • Start date Start date
E

Erik Jensen

Hi,

the subject says it all, A form has a textbox (which
doesnt allow 0 length strings) and has Validation set to
true. But I obviously dont want this event to return false
if Im closing the form or tabbing off the form.

Ive seen solutions that check for the mouse click vs. the
client rectangle to see if the user is clicking outside
the form area (i.e. the 'X' or some other window) and also
to check if they're Alt-TAB'ing . seen here:

http://www.dotnet247.com/247reference/msgs/9/45299.aspx

Are there more elegant solutions to this kind of
situation.

Thanks

Erik
 
Hello,

Erik Jensen said:
the subject says it all, A form has a textbox (which
doesnt allow 0 length strings) and has Validation set to
true. But I obviously dont want this event to return false
if Im closing the form or tabbing off the form.

Set the control's CausesValidation property to false before closing the
form.

HTH,
Herfried K. Wagner
 
You can set the forms validation to false before closing the form. I also
downloaded the MSDN Textbox validator and added in my own code to check for
instance like this. It sets a public Boolean for errors and checks for them
on closing. If there are errors, it displays a message telling the user of
the errors but still allows saving and closing.

Brian
 
Doesnt the textbox's Validate event fire before the form
loses focus in which case my form wont even get to the
OnClosing() event in which i would set the TextBox
Validation to false?

Or did you mean the whole form's validation to false?
And would that disallow or ignore individual control's
validation events from firing when the form closes?

Thanks
Erik
 
In the forms onclosing... I would think you could set the controls cause
validation to false and that would keep each control from validating.
 
-----Original Message-----
Hi,

the subject says it all, A form has a textbox (which
doesnt allow 0 length strings) and has Validation set to
true. But I obviously dont want this event to return false
if Im closing the form or tabbing off the form.

Ive seen solutions that check for the mouse click vs. the
client rectangle to see if the user is clicking outside
the form area (i.e. the 'X' or some other window) and also
to check if they're Alt-TAB'ing . seen here:

http://www.dotnet247.com/247reference/msgs/9/45299.aspx

Are there more elegant solutions to this kind of
situation.

Thanks

Erik
.
 
Back
Top