-
Aug 3rd, 2020, 04:21 PM
#1
Thread Starter
Addicted Member
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
-
Aug 3rd, 2020, 04:49 PM
#2
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
-
Aug 3rd, 2020, 05:57 PM
#3
Thread Starter
Addicted Member
Re: Make Tab Key work as Enter Key
Originally Posted by techgnome
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.
-
Aug 3rd, 2020, 10:28 PM
#4
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?
-
Aug 9th, 2020, 12:09 PM
#5
Hyperactive Member
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.
-
Aug 9th, 2020, 02:45 PM
#6
Re: Make Tab Key work as Enter Key
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)
-
Aug 9th, 2020, 08:11 PM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|