Without looping you can copy to an array and append.
// Create an array of all the items in DropDownList1
ListItem[] array = new ListItem[DropDownList1.Items.Count];
DropDownList1.Items.CopyTo(array, 0);
// Append them to DropDownList2
DropDownList2.Items.AddRange(array);
Marked as answer by smcirish on Jan 24, 2012 03:55 PM
smcirish
Member
732 Points
424 Posts
Moving items from one listbox to a new listbox
Jan 24, 2012 03:04 PM|LINK
Can I move all the items from ListboxA to ListboxB without looping?
How?
-smc
CollyMelon
Participant
997 Points
222 Posts
Re: Moving items from one listbox to a new listbox
Jan 24, 2012 03:10 PM|LINK
int mCount = ListboxA.Items.Count;
for (int i = 0; i <= mCount - 1; i++)
{
if (ListboxA.Items[i] == ListboxA.SelectedItem)
{
ListboxB.Items.Add(ListboxA.SelectedItem);
ListBox1.Items.Remove(ListboxA.SelectedItem);
mCount=mCount - 1; i=i - 1;
}
}
paulbentley
Member
588 Points
104 Posts
Re: Moving items from one listbox to a new listbox
Jan 24, 2012 03:14 PM|LINK
Without looping you can copy to an array and append.
kedarrkulkar...
All-Star
34013 Points
5468 Posts
Re: Moving items from one listbox to a new listbox
Jan 24, 2012 03:26 PM|LINK
listBoxB.Items.AddRange(listBoxA.Items);
hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
smcirish
Member
732 Points
424 Posts
Re: Moving items from one listbox to a new listbox
Jan 24, 2012 03:54 PM|LINK
Thanks Paul! Array answer worked great!
-smc