UserControl - Leave Event not being raised when press [ENTER] key

S

Simon Verona

I have a usercontrol with code in the "leave" event which updates the final
data back into a database.

This works fine except if I have a default "accept" button on a form and
invoke it by pressing the ENTER key on the keyboard. In this case, it would
appear that whilst the code on the button is executing and therefore
presumably the button actually has focus, the leave event in the user
control is not fired.

Should I be interfacing with another event on the usercontrol instead of the
"leave" event.. or is there some other way round the problem?

Thanks in advance
Simon
 
S

Simon Verona

I'm considering using the LostFocus event. instead of leave.. It looks like
they both get fired? Though it would appear that possibly the Leave event
doesn't get fired in the scenario I describe whereas the LostFocus even
does??? (I've not tested this yet but I'm presuming that it should).

So, to guarantee that my data gets updated, where should I put my updating
code? LostFocus? Leave? or perhaps should I use Validated or Validating???
Do I need to do the update in multiple events (with the pain of running the
update code twice???)

Hope somebody can ease my confusion!!

Regards
Simon
 
S

Simon Verona

I little investigation suggests that if I exit the usercontrol by pressing
ENTER to invoke the default Accept button on the form, that neither the
lostfocus or leave events are raised but the validated event is.

Am I therefore safe to put my update code in the validated event? Is this
guaranteed to be fired once and only once every time that my usercontrol is
exited, either by tabbing away, pressing enter or clicking elsewhere on the
form???

Thanks in advance
Simon
 

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