How do I move all items in a listbox to another listbox

K

kent

Hi All,

On my form, I have 2 listboxes that get populated with the correct items.
I have 4 buttons between the 2 boxes. The first 2 buttons are used to move
the selected item
back and forth between the boxes. That works fine.

The last 2 are used to move all the listbox items (whether they're selected
or not) that are in 1 box over to the other box.
After the move, I want the other box to be empty. I am calling clear() and
that works fine.
I am having trouble here and need help.

I have tried things like:
listbox1.items.addRange(listbox2.items)
listbox2.items.clear()

I have tried a couple of other things with no success.
I'm sort of a newbie, but I should be able to do this and I'm probably
making it much harder than it has to be.
Any help on how to do this would be greatly appreciated.

Remove the 'nospam' for email or send to (e-mail address removed)
 
A

Andrew de la Harpe

Try something list this (untested)

foreach(Listitem li in lstSrc)
{
lstDest.Items.Add( new ListItem(li.Text,Li.Value));
lstDest.Items.Remove(li);
}
 

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

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top