Results 1 to 4 of 4

Thread: 2 list

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    313

    Question

    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.

  2. #2
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi,
    Try This:

    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
    Reverse List1 and List2 around in the code to make it work the other way.

    Not sure about the scrollbar though!!

    hope this helps

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  3. #3
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    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

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    If you also want them to scroll simultaniously add the following code in the listbox scroll event:
    Code:
    Private Sub List1_Scroll()
        List2.TopIndex = List1.TopIndex
    End Sub
    
    Private Sub List2_Scroll()
        List1.TopIndex = List2.TopIndex
    End Sub
    This code might look like it causes recursion but it will not.

    Good luck!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width