That's correct. You cannot change a collection while you are looping
through it.
However, a simple change can allow you to do this:
dim alItemsToDelete as ArrayList = new ArrayList()
For Each li As ListItem In Me.lstAssignedE mailAddresses.I tems
If li.Selected = True Then
alItemsToDelete .Add(li)
Me.lstAssignedE mailAddresses.I tems.Remove(li)
End If
Next
For Each li as ListItem In alItemsToDelete
Me.lstAssignedE mailAddresses.I tems.Remove(li)
Next
Hope this helps
Ben Lucas
Lead Developer
Solien Technology, Inc.
www.solien.com
"VB Programmer" <Do************ *****@jEmail.co m> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Here's the code:
For Each li As ListItem In Me.lstAssignedE mailAddresses.I tems
If li.Selected = True Then
Me.lstAssignedE mailAddresses.I tems.Remove(li)
End If
Next
When I remove an item I get this error:
System.InvalidO perationExcepti on: Collection was modified; enumeration
operation may not execute. at
System.Collecti ons.ArrayListEn umeratorSimple. MoveNext()
I think its because I'm changing the collection while trying to loop
through it.
Any ideas for a workaround?
Thanks.