Click to See Complete Forum and Search --> : DATA between litsboxes


January 6th, 2000, 08:23 PM
how do I make it so when an item is clicked into list1, it is entered in the same spot in list2. I tried the following code:

Private Sub List1_Click()
a = list1.listindex
b$ = list1.list(a)
list2.additem b$, a

but when I try it, it keeps saying "INVALID PROCEDURE CALL OR ARGUEMENT..." What is wrong?

FStocker
January 7th, 2000, 02:18 AM
if you run your programm, the line:
list2.additem b$, a
makes the problem!
it only works, if you select the first item from list1 (a = 0),
if you select the 2nd 3rd... item it doesn't work, because you cannot add
a item to your list2 with index 1 2 3..., if the listbox is empty or has less than index(n) items
better you use list2.additem b$

i hope i could help you

valkyrie
January 7th, 2000, 02:40 AM
hi,
I think I can explain why there is a problem with your code. For example, I have a list:
"A"
"B"
"C"
and would like to add this from one listbox to another listbox when the user clicks on one of the items:


private Sub lstFirstBox_Click()
lstSecondBox.AddItem lstFirstBox.List lstFirstBox.ListIndex), lstFirstBox.ListIndex
End Sub




An error would occur if you click on B or C as when you try to add these items to the second listbox, the elements before are not added, since the "AddItem" method adds items to a listbox incremently from 0.

So, a workaround to this is to check if the first element has been chosen or not:


private Sub lstFirstBox_Click()

If (lstFirstBox.ListIndex = 1) then
'Add some dummy lines
lstSecondBox.AddItem vbNullString, 0
lstSecondBox.AddItem lstFirstBox.List(lstFistBox.ListIndex), lstFirstBox.ListIndex
ElseIf (lstFirstBox.ListIndex = 2) then
'Add 2 dummy lines
lstSecondBox.AddItem vbNullString, 0
lstSecondBox.AddItem vbNullString, 1
else
lstSecondBox.AddItem lstFirstBox.List(lstFirstBox.ListIndex), lstFirstBox.ListIndex
End If
End Sub




Here, I've done a little checking to see if the first element was clicked or not, if either B or C was clicked, an empty string will be added to the listbox.

Hope this does clears a few things up... try it!



____________________________________
The VB Bugs in my Life...