Moving Items from one Listbox to another

  • Thread starter Thread starter Elmo Watson
  • Start date Start date
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?
 
Hi,
Try this code:
for each currentItem as object in Me.ListBox1.Items

Me.ListBox2.Items.Add(currentItem)

next

Me.ListBox1.Items.Clear()
 
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
 
Back
Top