Results 1 to 7 of 7

Thread: Make Tab Key work as Enter Key

  1. #1

    Thread Starter
    Addicted Member dprontnicki's Avatar
    Join Date
    Sep 2016
    Posts
    151

    Make Tab Key work as Enter Key

    I have a combobox with auto complete mode set to SuggestAppend and source to ListItems. I have a key down event for when enter is pressed. I would like for the tab key to do the same thing.

    I have all controls with a tab stop set to False but the below code does not seem to work. Any ideas? Part of the GetProfesionals sub is to populate a label. It works for Enter but not Tab.

    Code:
        Private Sub CboSelectProfessional_KeyDown(sender As Object, e As KeyEventArgs) Handles CboSelectProfessional.KeyDown
    
            If (e.KeyCode = Keys.Enter OrElse e.KeyCode = Keys.Tab) Then
    
                GetProfessionals()
    
            End If
    
        End Sub

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,538

    Re: Make Tab Key work as Enter Key

    What does "code does not seem to work" mean? Do you get an error? Does milk suddenly come out our nose? Or is it orange juice? Did the wheels fall off your car? "Code does not work" is vague. It's like walking into the doc's office and saying "it hurts" and expecting him to figure it out. I don't know of anyone that does that. It's usually something specific - my shoulder hurts when I do this... or ... I was doing X when I fell and landed on my wrist.

    So... of course your code doesn't work, or you won't be here. So... what's supposed to happen that shouldn't? What's not happening that should? Error messages? Have you tried breakpoints and stepping through the code to see what's going on?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member dprontnicki's Avatar
    Join Date
    Sep 2016
    Posts
    151

    Re: Make Tab Key work as Enter Key

    Quote Originally Posted by techgnome View Post
    What does "code does not seem to work" mean? Do you get an error? Does milk suddenly come out our nose? Or is it orange juice? Did the wheels fall off your car? "Code does not work" is vague. It's like walking into the doc's office and saying "it hurts" and expecting him to figure it out. I don't know of anyone that does that. It's usually something specific - my shoulder hurts when I do this... or ... I was doing X when I fell and landed on my wrist.

    So... of course your code doesn't work, or you won't be here. So... what's supposed to happen that shouldn't? What's not happening that should? Error messages? Have you tried breakpoints and stepping through the code to see what's going on?

    -tg
    I have a combobox with a list of names in it. When you start typing a name it highlights the suggested name that you started typing. If you press enter it completes the name in the combobox and populates a label with the same name. When you press tab it dose neither. There are no errors, and have stepped through the code to see what is happening. It just doesn’t recognize the tab key at all.

    I believe it has to do with the fact that windows forms default for tab key is to go to the next tab stop. But I have removed all tab stops.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,347

    Re: Make Tab Key work as Enter Key

    Why have you set TabStop to False in the first place? Are you trying to prevent people tabbing between fields, as has been possible in Windows apps for decades, or was it an effort to get this functionality to work? If you have TabStop set to True then Enter will select the suggested item and Tab will select the suggested item and move to the next control, which is pretty much what most people would expect. With TabStop set to False, Enter selects the suggested item and closes the autocomplete list while Tab selects the suggested item without closing the autocomplete list. It seems like, if you really want TabStop set to False, the issue is actually closing the autocomplete list. What exactly does that GetProfessionals method do? Does it do anything to the ComboBox? Why would you be handling the KeyDown event rather than the SelectionChangeCommitted or SelectedIndexChanged event?

  5. #5
    Hyperactive Member
    Join Date
    Jan 2013
    Posts
    488

    Re: Make Tab Key work as Enter Key

    You may want to try this it works
    Code:
     
        Private Sub ComboBox1_PreviewKeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PreviewKeyDownEventArgs) Handles ComboBox1.PreviewKeyDown
            If (e.KeyCode = Keys.Enter OrElse e.KeyCode = Keys.Tab) Then
    
                MsgBox("hello")
            End If
        End Sub

    please read my current post about the tab key from yesterday.

  6. #6
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: Make Tab Key work as Enter Key

    Yes, you should have your answer here : https://www.vbforums.com/showthread....t=#post5489641
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  7. #7
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Make Tab Key work as Enter Key

    I don't understand exactly everything your trying to accomplish but if you want to put the contents of of the combobox in a label went it exits then the easiest way is is to use the Combobox Leave Event.

    Code:
        Private Sub ComboBox1_Leave(sender As Object, e As EventArgs) Handles ComboBox1.Leave
            Me.Label2.Text = Me.ComboBox1.Text
        End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width