Validating Data?

M

Mike

Hi,

In one of my winforms I am validating a textbox making sure it was filled
out and that the data is numeric and setting e.Cancel = true if not.
Everything works fine however the form has a OK and Cancel button. I do not
want the user be able to submit the form if the data is not correct (which
works fine by setting e.Cancel = true) however I want to the user to be able
to hit cancel and which closes the form. Right now by setting e.Cancel =
true does not allow me to close the form. But if do not use e.Cancel = true
then the user will be able to submit wrong data. Is there a way to get
around this?

Thanks
 
M

Mike

Nevermind I figured it out. All you need to do is test to see if the Cancel
Button has focus in the validating event of each control.
 
O

Otis Mukinfus

Nevermind I figured it out. All you need to do is test to see if the Cancel
Button has focus in the validating event of each control.

You should also be able to set the CausesValidation property of the
Cancel button to false. If you do that no validation will be done
when the user clicks the cancel button. Then you won't have to check
which control has focus...

Otis Mukinfus
http://www.otismukinfus.com
 

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