Home All Groups Group Topic Archive Search About

how to trap/detect when entering textbox via tabkey?

Author
7 Jul 2006 4:14 PM
Rich
Hello,

I need to trap/detect when a textbox is entered via the tabkey.  If the
textbox is not empty when entered via the tabkey then set focus to next
textbox.  To enter that textbox would then require a mouseclick if it already
contains text to be edited.    I am guessing that I would need to trap for
this in the Enter Event of this particular textbox. 

I tried this in the Enter Event of the Textbox, but...

if ctype(sender,KeyValuePair(Of, " "))

obviously not working.  I would be very grateful if someone could share how
to trap/detect when entering a textbox via the tabkey.

Thanks,
Rich

Author
7 Jul 2006 4:22 PM
iwdu15
check out the textbox's GotFocus event. that is fired whenever the control
gets the focus, be it by the mouse or tab key, etc
--
-iwdu15
Author
7 Jul 2006 4:34 PM
Rich
Well, I came up with this

Private Sub txtM_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtM.KeyUp
        If e.KeyCode.ToString.Equals("Tab") Then
            If txtM.Text <> "" Then txtlastName.Focus()
        End If
End Sub

Interestingly, it was the KeyUp event of the textbox where you can trap for
the tab key.  Anyway, this seems to do what I want.  Any other suggestions
appreciated.

Show quoteHide quote
"Rich" wrote:

> Hello,
>
> I need to trap/detect when a textbox is entered via the tabkey.  If the
> textbox is not empty when entered via the tabkey then set focus to next
> textbox.  To enter that textbox would then require a mouseclick if it already
> contains text to be edited.    I am guessing that I would need to trap for
> this in the Enter Event of this particular textbox. 
>
> I tried this in the Enter Event of the Textbox, but...
>
> if ctype(sender,KeyValuePair(Of, " "))
>
> obviously not working.  I would be very grateful if someone could share how
> to trap/detect when entering a textbox via the tabkey.
>
> Thanks,
> Rich