Please help!

  • Thread starter Thread starter A newbie in trouble
  • Start date Start date
A

A newbie in trouble

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
 
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
 
Hello,

A newbie in trouble said:
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
 
Back
Top