scrolling through combo box with arrow keys

M

Miranda

hi,

is there a way to scroll through the values in a combo box with the arrow
keys. so if i tab to this combobox i can just use the down arrow to find a
value?

thanks
miranda
 
D

Dirk Goldgar

Miranda said:
hi,

is there a way to scroll through the values in a combo box with the
arrow keys. so if i tab to this combobox i can just use the down
arrow to find a value?

You can use the down-arrow key, but only after the combo box has been
"dropped down." Pressing the F4 key when the combo box has the focus
will drop it down. If you want, you can use code in its GotFocus event
to make it drop down automatically; for example:

Private Sub cboMyCombo_GotFocus()

Me.cboMyCombo.Dropdown

End Sub

I personally don't like combo boxes to drop down automatically as I tab
through them, but you can try it and make your own decision.

Note: it's possible to detect whether a combo box is in its
dropped-down state or not, but it's quite complicated. So while
theoretically you could trap the down-arrow keypress and use it to drop
down the combo box if it isn't already dropped down, I don't know if you
want to pursue that course.
 
S

Stephen Lebans

THe code below is for a ListBox but it should work with a Combo control
as well.

If you'd like to use the Arrow Keys to navigate through a ListBox even
if the ListBox does not have the focus then read on.



Go to Form properties and set the Key Preview to Yes.

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

Select Case KeyCode

Case vbKeyDown
Me.List2 = Me.List2.ItemData(Me.List2.ListIndex + 1)
KeyCode = 0


Case vbKeyUp
Me.List2 = Me.List2.ItemData(Me.List2.ListIndex - 1)
KeyCode = 0

Case Else
End Select

End Sub

Tthe above code is for a ListBox named List2. Change the name to reflect
your ListBox. Also this is set to work with a ListBox WITHOUT Column
Headers turned on. You'll have to adjust it if you use Column Headers.
Finally the Arrow Keys are sent to oblivion with the Line KeyCode =0.



--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top