is there any way to move through a list box such that when your at index o a keypress up will bring you to the last index and vice versa if you're at the last record and a key press down will bring you to index 0 and help would be a ppreciated thanks
Use the ListBox's KeyDown event to test for the up/down arrow keys. The box's ListIndex property tells you the currently selected row, so your code would be something like this:
Code:
With ListBox1
If KeyCode = vbKeyUp And .ListIndex = 0 Then
.ListIndex = .ListCount - 1
KeyCode = 0
ElseIf KeyCode = vbKeyDown And .ListIndex = .ListCount - 1 Then
.ListIndex = 0
KeyCode = 0
End If
End With
Note: If you're going to process the keystroke instead of letting the list box do it, you need to "eat" the keystroke by setting KeyCode to 0. Otherwise, the list box will process it again after you, which will result in double movement.
Rick Sprague
Want the best answers? See faq181-2886 To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.