I am working on what I have come to call a "Mover Box". That is, two listboxes with buttons between them to allow the user to move selections from one box to the other.
The process has 2 steps:
1. Taking the selection(s) made in one box and adding them to the other.
2. Removing them from the originating listbox.
Step 1 went smoothly with this code:
Code:
Dim li As ListItem
For Each li In lbOrigin.Items
If li.Selected Then
lbDestination.Items.Add(New ListItem(li.Text, li.Value))
End If
Next
However, I thought that step 2 would be as straightforward with this code:
Code:
For Each li In lbOrigin.Items
If li.Selected Then
lbOrigin.Items.Remove(li)
End If
Next
When I run this code, step 2 generates the error, "Collection was modified; enumeration operation may not execute."
I'm having trouble finding a way around this. I have tried a few avenues, but all were dead ends.
Any ideas on how I can remove these items successfully?
- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.