Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remove item from multi select listbox 2

Status
Not open for further replies.

compucop

Technical User
Joined
Sep 24, 2002
Messages
107
Location
US
Hi, I am using two multi select listboxes that transfer data from one listbox to another. My code is the following.

dim (i) as integer

Dim i As Integer


For i = 0 To List1.ListCount

If List1.Selected(i) = True Then

Me.List2.AddItem Me.List1.Column(0, i)
me.list1.removeitem (i)
End If
Next i

* Problem is the me.list1.removeitem(i) code, it only transfers one name from the listbox and removes only one item. it does not remove the multi-selection. Any help greatly appreciated.
 

Try working in the other direction. Deleting items affects the collection and the index numbers.

e.g.:
Code:
For i = List1.ListCount to 0 step -1
 
Tried it, no luck. Thanks for post.
 
Hmm.. since that excellent suggestion didn't work, maybe you should just try doing it in two steps.

dim ItemArray() as variant
dim ItemArraySize as integer
dim ItemArrayEls as integer

ItemArraySize = 0
ItemArrayEls = 0

For i = 0 To List1.ListCount

If List1.Selected(i) = True Then
if ItemArrayEls >= ItemArraySize then
ItemArraySize = ItemArraySize + 32
redim preserve ItemArray(ItemArraySize)
endif
ItemArray(ItemArrayEls) = Me.List1.Column(0, i)
ItemArrayEls = ItemArrayEls + 1
endif
Next i

for i = 0 to ItemArrayEls - 1
Me.List2.AddItem ItemArray(i)
next i

for i = 0 to ItemArrayEls - 1
me.list1.removeitem (i)
Next i

 
beetee, already did it your way. Finished it and then saw your post, if only i posted earlier. Thanks both of you guys for your help. Later.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top