C
COHENMARVIN
I've been doing a simple for-each loop to remove multiple selected
items from one listbox, and to dump them in another listbox.
for each item in LeftListBox.Items
if (item.Selected = true) Then
RightListBox.Items.Add(item)
LeftListBox.Items.Remove(item)
End If
Next
The problem is that this code doesn't work because its modifying the
collection in the left listbox. I get an error such as:
"Collection was modified; enumeration operation may not execute".
I searched the internet for an explanation, and I see one person who
says that you cannot use For-each in a situation like this, instead you
should use For-Next. My question: How do you iterate through a listbox
with for-next?
Thanks,
Marvin
items from one listbox, and to dump them in another listbox.
for each item in LeftListBox.Items
if (item.Selected = true) Then
RightListBox.Items.Add(item)
LeftListBox.Items.Remove(item)
End If
Next
The problem is that this code doesn't work because its modifying the
collection in the left listbox. I get an error such as:
"Collection was modified; enumeration operation may not execute".
I searched the internet for an explanation, and I see one person who
says that you cannot use For-each in a situation like this, instead you
should use For-Next. My question: How do you iterate through a listbox
with for-next?
Thanks,
Marvin