|
-
Nov 5th, 2005, 10:01 AM
#1
Thread Starter
Frenzied Member
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
-
Nov 5th, 2005, 10:54 AM
#2
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:
Private Sub List1_Click()
List2.ListIndex = List1.ListIndex
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:
Private Sub cmdDelete_Click()
List2.RemoveItem List1.ListIndex
List1.RemoveItem List1.ListIndex
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|