Please help!  
Author Message
roller





PostPosted: Mon Aug 11 14:25:43 CDT 2003 Top

Winforms >> Please help! Hi,

I'm having some strange problem in a windows application
in vb.net. On my form I have two ListBox, and when I try
to add or remove items from the: myListBox.Items, I have
the following error message:

"The list that this enumerator is bound to has been
modified. An enumerator can only be used if the list
doesn't change."

Any idea what happens?
I have not bound the Listbox to anything.

thanks,


Tina

DotNet198  
 
 
Bill





PostPosted: Mon Aug 11 14:25:43 CDT 2003 Top

Winforms >> Please help! Yes. you are modifying a list while iterating through it
using a For Each statement.

Something like this?

For Each CollectionItem In MyCollection
if CollectionItem == somevalue then
MyCollection.Remove(CollectionItem)
end if
Next CollectionItem

Sorry if its not true VB syntax, im more of a C# person.
Anyway thats not allowed. you will have to iterate the
list using another looping structure such as a while loop.

Bill

>-----Original Message-----
>Hi,
>
>I'm having some strange problem in a windows application
>in vb.net. On my form I have two ListBox, and when I try
>to add or remove items from the: myListBox.Items, I have
>the following error message:
>
>"The list that this enumerator is bound to has been
>modified. An enumerator can only be used if the list
>doesn't change."
>
>Any idea what happens?
>I have not bound the Listbox to anything.
>
>thanks,
>
>
>Tina
>.
>
 
 
Herfried





PostPosted: Mon Aug 11 15:20:28 CDT 2003 Top

Winforms >> Please help! Hello,

"A newbie in trouble" <EMail@HideDomain.com> schrieb:
> I'm having some strange problem in a windows application
> in vb.net. On my form I have two ListBox, and when I try
> to add or remove items from the: myListBox.Items, I have
> the following error message:
>
> "The list that this enumerator is bound to has been
> modified. An enumerator can only be used if the list
> doesn't change."

Do you remove the items in a For...Each loop?

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet