Link to home
Start Free TrialLog in
Avatar of norway77
norway77

asked on

disable tab keystroke in text field in vb.net form

How can i trap for a tab key pressed and disable the action.  Or turn the tab key into a return key to call a function i have in the return key

The whole idea is to change the value of an input field when the user leaves that field.  I have a function that works on with the return key but not with the tab key.

thanks
danny
Avatar of JackOfPH
JackOfPH
Flag of Philippines image

ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of norway77
norway77

ASKER

Ok, better definition:

I want to go thru a form with multiple textboxs and edit the fields as I go. Using the txtbox1.keydown and txtbox1.keypress I seem to be able yo captue the [Enter] key, validate the data and either move to the next txtbox2 if good or display an error message and re-focus on the current txtbox1.  The problem is these methods do not seem to trap the [Tab] key - which then bypasses my edits.  Using the following code I am able to capture the tab key, validate the data but I cannot suppress the key and re focus on the current txtbox...

        Protected Overrides Function ProcessCmdKey(ByRef msg As Message, _
                           ByVal keyData As Keys) As Boolean
        Const WM_KEYDOWN As Integer = &H100
        Const WM_SYSKEYDOWN As Integer = &H104

        If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
            Select Case (keyData)

                Case Keys.Tab
                    'MsgBox("Tab Key Captured in the " + Me.ActiveControl.Name + " control!")

                    'I can do something based on the active control
                    Select Case Me.ActiveControl.Name
                          case TxtBox1
                               if not  validatedata1() then
                                   DON'T PROCESS TAB KEY!!!  ?????
                               end if
                    end select

Any way to not tab here?
Thanks,