how can i merge two lists into one, this is the main question.
these two listboxes contain, three items: Name, Phone, Address.
Now how can they both be merged???
Printable View
how can i merge two lists into one, this is the main question.
these two listboxes contain, three items: Name, Phone, Address.
Now how can they both be merged???
do you mean like list1 items on top of list2 items?
no i mean it merges the two of them into one so that if one lising exists in the other list the merged list would only contain one of those listings. Meaning if one Name, Phone, Address is in list #1 and in list #2 then when i merge the merge list will only have one Name, Phone, Address and not the same thing twice.
I guess you need something like this:
Code:For x = 0 To List1.ListCount
For y = 0 To List2.ListCount - 1
If List1.List(x) Like List2.List(y) Then Exit For
Next y
If y = List2.ListCount Then List2.AddItem List1.List(x)
Next x
i have tried the above method but it doesn't seem to work, please advise an other way. remember its like putting the two lists together, and taking out duplicate items
The code should work, but depends how you want the result to be. It goes trough each item in list1 and compares it with all items in list2, and refueses to add it whenever it founds a match.
it only adds the items from the first list to the lstmerged it doesn't add any of the items from the second list
Well why didn't you say so?
Code:For y = 0 To List2.ListCount - 1
lstmerged.AddItem List2.List(y)
Next y
For x = 0 To List1.ListCount
For y = 0 To List2.ListCount - 1
If List1.List(x) Like List2.List(y) Then Exit For
Next y
If y = List2.ListCount Then lstmerged.AddItem List1.List(x)
Next x