RSchnabel
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(s ender 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?
Private Sub tbOrderNumber_Validating(s
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?
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 TRIALMembers 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.
Or, perhaps it's something to do with the order of events detailed here.