Results 1 to 5 of 5

Thread: Listboxes

  1. #1

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Listboxes

    I have 11 list boxes,

    I need it so that if I select the top item on the first list box it selects the first option on the other 10, and it does the same so that if I pick the 356th item on the list box, it pick the 356th item on all the other list boxes

  2. #2
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: Listboxes

    It becomes much simpler if you are using an array of listbox controls.

    Here is the meat of the select
    VB Code:
    1. Private Sub List1_Click(Index As Integer)
    2.     Dim NewIdx As Integer
    3.     Dim i As Integer
    4.     NewIdx = List1(Index).ListIndex
    5.     For i = 0 To List1.Count - 1
    6.         List1(i).Selected(NewIdx) = True
    7.     Next i
    8. End Sub

    Here is the form
    Attached Files Attached Files

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Listboxes

    Assuming you have a control array and assuming the number of items in each listbox are the same.

    VB Code:
    1. Private Sub List1_Click(Index As Integer)
    2.     Dim lngIdx As Long
    3.     If Index = 0 Then
    4.        For lngIdx = List1.LBound + 1 To List1.UBound
    5.            List1(lngIdx).ListIndex = List1(0).ListIndex
    6.        Next
    7.     End If
    8. End Sub

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Listboxes

    The Control Array as mentioned above is the way to go. However if you
    haven't used on, then this may be a place to start:
    VB Code:
    1. Private Sub List1_Click()
    2.     Call Update_All_ListBoxs(List1, List1.ListIndex)
    3. End Sub
    4.  
    5. Private Sub List2_Click()
    6.     Call Update_All_ListBoxs(List2, List2.ListIndex)
    7. End Sub
    8.  
    9. Private Sub List3_Click()
    10.     Call Update_All_ListBoxs(List3, List3.ListIndex)
    11. End Sub
    12.  
    13. Private Sub Update_All_ListBoxs(ByRef lstBox As ListBox, ByVal intIdx As Integer)
    14. Dim ctl As Control
    15.  
    16.     For Each ctl In Me.Controls
    17.         If TypeOf ctl Is ListBox And ctl <> lstBox Then ctl.ListIndex = intIdx
    18.     Next
    19. End Sub

    Edit: The draw back with this method, is the Sub gets fired each time a ListBox is updated (simulated Click) by the actual Sub.
    Last edited by Bruce Fox; Sep 27th, 2005 at 04:39 PM.

  5. #5
    Lively Member
    Join Date
    Aug 2005
    Location
    Missouri
    Posts
    69

    Re: Listboxes

    The index method seems the way to go, the only addendum I have to it is make sure that you put it on a keypress event also (actually, if memory serves you only need it on a keypress event, but I'm often wrong) That way if your user gets ants in their pants and decides to scroll the box with up/down arrows, it will scroll all of them. The only problem I've encountered with this is that if someone decides to grab the scroll bar and move one box, the other boxes don't move. I like to see my highlighted line run straight, and while it will still highlight all the correct items, sometimes the line won't be straight if the scroll bars have been repositioned.

    Don't listen to me.

    P.S. The one by Bruce only allows the first list box to control the others, remove the If index = 0 / end if if you want all the boxes to control one another.

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