Validating on the OK click

G

Guest

Hi there,

I have a form that requires the user to enter two dates where the first must
be before the second. I only want to validate the dates when the user clicks
the OK button.

I've tried using the validating events but the best I was able to accomplish
was to have the validating event fire for the group box that contains the
date entry controls. The problem that occurs then is that the event fires
because the user clicked on the OK button. That seems to cancel out the OK
click and you have to click OK again.

I then tried to do the validation during the OK button clicked event.
Unfortunately, I can't figure out how to cancel the click event if there is a
problem with the date. I'm able to pop up an error message, but then it just
continues to close down the form and return to the calling form. Is there a
clean way to do it?


Thanks,

Carlo.
 
C

Claes Bergefall

Don't set the AcceptButton property on your form
In your click event handler call Close if everything is valid

/claes
 

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