Any way to select Listbox items via keyboard?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Any way to select Listbox items via keyboard

I am trying to minimize use of mouse due to RSI injury.
 
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.

Your mileage may vary. :-)


--

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

case VbRetur
Call Me.List2_clic

to enable seklection via Enter ke
Thanks

- Davi

----- Stephen Lebans wrote: ----

If you'd like to use the Arrow Keys to navigate through a ListBox eve
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 KeyCod

Case vbKeyDow
Me.List2 = Me.List2.ItemData(Me.List2.ListIndex + 1
KeyCode =


Case vbKeyU
Me.List2 = Me.List2.ItemData(Me.List2.ListIndex - 1
KeyCode =

Case Els
End Selec

End Su

Tthe above code is for a ListBox named List2. Change the name to reflec
your ListBox. Also this is set to work with a ListBox WITHOUT Colum
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

Your mileage may vary. :-


-

HT
Stephen Leban
http://www.lebans.co
Access Code, Tips and Trick
Please respond only to the newsgroups so everyone can benefit
 
Back
Top