mcrmg
asked on
move items from one listbox to another
Hi,
The following is my code, I am trying to move items from one listbox to another. But I am getting
System.InvalidOperationExc eption: Collection was modified; enumeration operation may not execute.
I guess it is because as item in listBox1 was removed, the count is different.
The following is my code, I am trying to move items from one listbox to another. But I am getting
System.InvalidOperationExc
I guess it is because as item in listBox1 was removed, the count is different.
protected void MoveMultibtn_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex == -1)
{
testBox.Text = "Please select an item";
}
else
{
foreach (ListItem item in listBox1.Items)
{
if (item.Selected)
{
listBox2.Items.Add(item);
listBox1.Items.Remove(listBox1.SelectedItem);
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER