all groups > dotnet windows forms > november 2007 >
You're in the

dotnet windows forms

group:

Moving Items from one Listbox to another


Moving Items from one Listbox to another Elmo Watson
11/12/2007 3:04:15 PM
dotnet windows forms:
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?


RE: Moving Items from one Listbox to another Manish Bafna
11/12/2007 9:34:00 PM
Hi,
Try this code:
for each currentItem as object in Me.ListBox1.Items

Me.ListBox2.Items.Add(currentItem)

next

Me.ListBox1.Items.Clear()
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



[quoted text, click to view]
Re: Moving Items from one Listbox to another Elmo Watson
11/12/2007 11:47:40 PM
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


[quoted text, click to view]

AddThis Social Bookmark Button