Textbox-level validation

  • Thread starter Thread starter Marc Scheuner [MVP ADSI]
  • Start date Start date
M

Marc Scheuner [MVP ADSI]

Folks,

I have a C# WinForms app, and I am doing some validation of text boxes
and their contents.

So far, I've used the TextBox1_Leave event - if the focus goes away
from the textbox, I check for certain conditions (not empty, valid
entry etc.).

This works okay so far - but in some cases, I'd like to skip that
validation, e.g. when the user clicks on the "Cancel" button.

But how can I "foresee" that the user has clicked the Cancel button,
inside my TextBox1_Leave event?? In Delphi, we used to be able to
inspect a property "ActiveControl" which was set to the button that
had been clicked - based on that info, I was able to determine whether
or not I wanted to apply my validation.

I don't seem to find anything similar in C# / .NET - I do have an
"ActiveControl" property, but that is still set to my text box, as
long as I'm still on it.....

Any way to achieve what I'm trying to do without major kludges??

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Why don't you use the validating event. Set causesvalidation
property of the cancel button to false.

Indeed, why..... well, thanks for the hint - that works nicely!

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top