By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 ks*******@yahoo.com
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Try something list this (untested)

foreach(Listitem li in lstSrc)
{
lstDest.Items.Add( new ListItem(li.Text,Li.Value));
lstDest.Items.Remove(li);
}
"kent" <ks*******@nospam.comcast.net> wrote in message
news:Y_********************@comcast.com...
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 ks*******@yahoo.com

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.