Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looping through listboxes

Status
Not open for further replies.

MBall2003

Programmer
Joined
May 30, 2003
Messages
61
Location
US
i have a list box populated with employee names, about 20 employees. how do i get it where when the last item in the list box is selected and the user presses down they go back to the first item vice versa for when the first itme is selected and the users presses up, go to the bottom
any ideas would be appreciated thanks

mball
 
MBall2003,

Try this (substitute you lisbox control name for "List0":

Code:
Private Sub List0_KeyUp(KeyCode As Integer, Shift As Integer)

Dim iItemsInList As Integer
iItemsInList = Me.List0.ListCount - 1

If KeyCode = vbKeyUp And Me.List0.ListIndex = 0 Then
    Me.List0.Selected(iItemsInList) = True
ElseIf KeyCode = vbKeyDown And Me.List0.ListIndex = (iItemsInList) Then
    Me.List0.Selected(0) = True
End If
End Sub

Heather

[yinyang] [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top