Link to home
Start Free TrialLog in
Avatar of RSchnabel
RSchnabelFlag for United States of America

asked on

Validating event firing twice when Tab is pressed.

I am very new to .net but have but lots of years of vb 6 and before. Very simple form has a textbox and I have the following validating code:

  Private Sub tbOrderNumber_Validating(sender As Object, e As CancelEventArgs) Handles tbOrderNumber.Validating
        If Not tbOrderNumber.Text Like "########" Then
            e.Cancel = True
            MessageBox.Show("Invalid order number, please enter a valid order number.")
        End If

    End Sub

I have stripped all other code out of solution, This code works as I would expect it to, if the mouse is used to move somewhere else, but if a Tab is pressed it fires this sub twice. Why?
Avatar of Norie
Norie

Could it be that the tab is being recognised as a key press and triggering the code?

Or, perhaps it's something to do with the order of events detailed here.
Avatar of RSchnabel

ASKER

I would think that a tab being pressed on the key board would trigger a key press event, but I am not clear why that would trigger the validating event twice. I get that the order of events change based on if the mouse is used or the tab is used but I would think that it would only trigger the validating once not twice? Hmmmm.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.