Moving Items from one Listbox to another

E

Elmo Watson

I've got this code, and it doesn't really work correctly:
For Each ind In Listbox1.SelectedIndices
Dim id As String = Listbox1.Items.Item(ind).ToString
Listbox2.Items.Add(id)
Listbox1.Items.remove(ind)
Next

I am trying to move items from Listbox1 to Listbox2 (by moving, I mean when
they are added to #2, I want to remove them from #1).

Every time I remove an item, it resets the index - - - I've been trying to
find sample code on the net, but apparently my search words aren't returning
the correct samples.

Can someone help me get this right?
 
G

Guest

Hi,
Try this code:
for each currentItem as object in Me.ListBox1.Items

Me.ListBox2.Items.Add(currentItem)

next

Me.ListBox1.Items.Clear()
 
E

Elmo Watson

Thanks - but I think you misunderstood me

I need to only move the Selected Items (the listbox is multi-select) over to
listbox2 - -
Then, once they're added to listbox2, only remove the selected Items from
listbox1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top