Results 1 to 5 of 5

Thread: Leave event not triggered when access key activated for button

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    43

    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?

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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'?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    43

    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

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width