Leave event not triggered when access key activated for button
I have a textbox on a form. I have a procedure to check the validity of entry when the LEAVE event for that textbox takes place. There is also a button to exit the form which has an access key. if I click on the button the LEAVE event is triggered, but if I use the ALT-character to "click" the button the LEAVE event for the textbox is not triggered. How can I do it for the latter situation?
Re: Leave event not triggered when access key activated for button
Why aren't you doing this on the button click event making it irrelevant how the button is 'pressed'?
Re: Leave event not triggered when access key activated for button
Because I actually have dozens of textboxes, each with its own validity-checking routine, and each must checked when that box is left rather than all at once at the end
Re: Leave event not triggered when access key activated for button
Not sure that this is really the best event for validation (that's what the validation events are for!) but the easiest way to force a leave is ...
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Button1.Focus()
End Sub
... which will work however the click is invoked.
Re: Leave event not triggered when access key activated for button
You shouldn't be using the Leave event for validation. As dunfiddlin says, that's what the validation events are for. You should be handling the Validating event, not Leave. When you use the accelerator key to "click" a Button it does not receive focus, so of course the Leave event of the TextBox isn't raised, because focus doesn't leave the TextBox. Both the Validating and Validated events will be raised though, because they are designed to be used for validation.