Results 1 to 2 of 2

Thread: 2 Dependent ListBoxes!

  1. #1

    Thread Starter
    Frenzied Member arpan_de's Avatar
    Join Date
    Oct 2005
    Location
    Mumbai, India
    Posts
    1,394

    Unhappy 2 Dependent ListBoxes!

    A VB6 Form has 2 ListBoxes. Both of them have 4 items. The items in the 1st ListBox are A, B, C & D. The items in the 2nd ListBox are Apple, Ball, Cat & Dog.

    Assume that a user has selected B in the 1st ListBox. Under such circumstances, the item Ball in the 2nd ListBox should get selected automatically {B for ball ). Next the user selects D in the 1st ListBox. Under such circumstances, the item Dog in the 2nd ListBox should get selected automatically {D for dog ). Next the user selects A in the 1st ListBox. Under such circumstances, the item Apple in the 2nd ListBox should get selected automatically {A for apple ) so on & so forth.

    How do I implement this? Also I want that if an item in the 1st ListBox is deleted, its corresponding item in the 2nd ListBox should also get deleted automatically. For e.g. if the user deletes C in the 1st ListBox, the item Cat should automatically get deleted from the 2nd ListBox {C for Cat ).

    Thanks,

    Arpan

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: 2 Dependent ListBoxes!

    If you always have the same amount of items and the corresponding items have the same ListIndex you can easily do it this way:
    VB Code:
    1. Private Sub List1_Click()
    2.     List2.ListIndex = List1.ListIndex
    3. End Sub
    To delete the items you do pretty much the same way. Let's say you have a Command Button, named cmdDelete, which will delete the selected item from both lists.
    VB Code:
    1. Private Sub cmdDelete_Click()
    2.     List2.RemoveItem List1.ListIndex
    3.     List1.RemoveItem List1.ListIndex
    4. End Sub

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