?
Solved

disable tab keystroke in text field in vb.net form

Posted on 2009-04-29
3
Medium Priority
?
459 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:norway77
3 Comments
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24266812
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 375 total points
ID: 24272447
You can do something like this:
    Protected Overrides Function ProcessTabKey(ByVal forward As Boolean) As Boolean
        If Me.TextBox1.Focused Then
            Return True
        Else
            Return MyBase.ProcessTabKey(forward)
        End If
    End Function

Open in new window

0
 

Author Comment

by:norway77
ID: 24275254
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,
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question