Lets say i have 2 list. they are right next to eachother, and say on the first list i click the 5th item. how can i highlight the 5th item in the second list. and vice versa.
also how can i change the scroll bar thing.
Printable View
Lets say i have 2 list. they are right next to eachother, and say on the first list i click the 5th item. how can i highlight the 5th item in the second list. and vice versa.
also how can i change the scroll bar thing.
Hi,
Try This:
Reverse List1 and List2 around in the code to make it work the other way.Code:Private Sub List1_Click()
Dim i As Integer
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then List2.Selected(i) = True
Next i
Not sure about the scrollbar though!! :)
hope this helps
Shaun
Add 2 Listboxes to a Form as a Listbox Control Array:Code:Private Sub Form_Load()
'Generate some Dummy List Items
Dim lIndex As Long
For lIndex = 1 To 100
lstLists(0).AddItem "Item " & Right("000" & lIndex, 3)
lstLists(1).AddItem "Item " & Right("000" & lIndex, 3)
Next
End Sub
Private Sub lstLists_Click(Index As Integer)
Static bAligning As Boolean
Dim lOtherList As Long
'Use a Static Boolean Var to prevent recursion (setting the ListIndex triggers the "Click" Event)
If bAligning Then Exit Sub
'Flag that we're performing an Alignment operation
bAligning = True
'Get the Index of the "Other" Listbox
lOtherList = (Index + 1) Mod 2
'If there is a matching Item in the Other Listbox...
If lstLists(lOtherList).ListCount >= lstLists(Index).ListIndex Then
'Select the same Item...
lstLists(lOtherList).ListIndex = lstLists(Index).ListIndex
'Make the TopIndex Match too (Keeps both aligned)
lstLists(lOtherList).TopIndex = lstLists(Index).TopIndex
End If
'Reset the Alignment flag
bAligning = False
End Sub
If you also want them to scroll simultaniously add the following code in the listbox scroll event:
This code might look like it causes recursion but it will not.Code:Private Sub List1_Scroll()
List2.TopIndex = List1.TopIndex
End Sub
Private Sub List2_Scroll()
List1.TopIndex = List2.TopIndex
End Sub
Good luck!