Link to home
Start Free TrialLog in
Avatar of norway77
norway77

asked on

enable/disable tab function in vb.net form


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...


Any way to not tab here?
Thanks,
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

Open in new window

Avatar of CyberLex
CyberLex
Flag of Switzerland image

DON'T PROCESS TAB KEY!!!  ????? = return true

simple as that

:) cheers
Alex
ASKER CERTIFIED SOLUTION
Avatar of oobayly
oobayly
Flag of United Kingdom of Great Britain and Northern Ireland 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

oobayly,
that worked great.
thanks