473,320 Members | 2,088 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do you allow arrow keys in a combo box

Michael Adams
I have multiple combo boxes which I have a tab order on. The problem that I am having right now is is that when you tab to a combo box and try to go down through the data and use the down arrow on the keyboard the cusor goes to the next tab count item.

What do I do to allow the use of arrow keys in the combo box when it has the focus?

Thanks in Advance.
Jul 29 '10 #1
2 6342
missinglinq
3,532 Expert 2GB
Replacing Combo with the actual name of your combobox:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo_KeyDown(KeyCode As Integer, Shift As Integer)
  2.  
  3.   Select Case KeyCode
  4.     Case vbKeyDown
  5.       If Combo.ListIndex <> Combo.ListCount   1 Then
  6.         Combo.ListIndex = Combo.ListIndex + 1
  7.       Else
  8.         Combo.ListIndex = 0
  9.       End If
  10.    Case vbKeyUp
  11.       If Combo.ListIndex <> 0 Then
  12.         Combo.ListIndex = Combo.ListIndex   1
  13.       Else
  14.         Combo.ListIndex = Combo.ListCount   1
  15.       End If
  16. End Select
  17.  
  18. End Sub
  19.  
In order to keep focus from leaving the combobox when you get to the beginning or the end of the selections, I have it "wrapping." If you get to the last selection and hit the Down Arrow again, it wraps back to the first selection ; if you're on the first selection and hit the Up Arrow it wraps around to the last selection.

Remember, if for some reason you use this code elsewhere, without the combobox having the focus, you need to set focus on it before executing the code.

Linq ;0)>
Jul 29 '10 #2
ADezii
8,834 Expert 8TB
@Michael Adams
On the GotFocus() Event of your Combo Boxes, Drop Down the Combo Box. Now, the Arrow Keys should behave as you expect. For a Combo Box named Combo1:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo1_GotFocus()
  2.   Me![Combo1].Dropdown
  3. End Sub
Jul 29 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Paul Nathan | last post by:
While trying to write a simple game which uses the arrow keys, I noticed that under the subroutine that handles mybase.keydown, everytime I pressed any arrow keys, or in fact any of the 9 keys...
2
by: Darren Oakey | last post by:
ok - the problem - I made a simple breakout game out of a form, just painting the background - and using keydown for left and right arrow keys to control the bat - worked fine. I then moved all...
1
by: bj | last post by:
How to process arrow keys? Hello I need to catch arrow keys down event from control derivied from usercontrol -OnKeyDown method seems to work for all keys besides arrow keys -however OnKeyUp...
4
by: Neil Wallace | last post by:
Hi there, I have an application in which a grid of 100 or more buttons are put on a form in columns of 10. All the buttons are within a panel. They are added in runtime, and so they adopt a...
11
by: Rlrcstr | last post by:
How can you detect when an arrow key gets pressed? Doesn't seem to trigger a KeyPress or KeyDown event. Thanks. Jerry
2
by: Vincent | last post by:
Hi, I have a user control that needs to trap the arrow keys to move items around internally. However, using the arrow keys will move the focus to another control on the form hosting the user...
1
by: Martijn Mulder | last post by:
/* I have problems detecting the Arrow Keys on a User Control. A control derived from System.Windows.Forms.Control neglects 'bare' Arrow Keys but does react on the combination <Altor <Ctrl+ Arrow...
9
by: Laphan | last post by:
Hi All I'm using the below to limit the input into a text box to just letters, numbers, hyphens and full stops, but I also need to allow the backspace, delete and arrow keys to come through. ...
4
by: boopsboops | last post by:
Hi thescripts people, I hope I'm in the right forum for Visual Basic Dotnet (VS 2005). I am trying to make a custom control in which you can nudge a point around using the arrow keys. Actually,...
0
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
When I have an editable combobox in a DataGridView and the user tries to correct an error they can not move the cursor from character to character with the arrow keys. The arrow keys move focus...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.