By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

How do you allow arrow keys in a combo box

Michael Adams
P: 55
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
Share this Question
Share on Google+
2 Replies


missinglinq
Expert 2.5K+
P: 3,532
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
Expert 5K+
P: 8,699
@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

Post your reply

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