listbox problem

  • Thread starter Heath P. Dillon
  • Start date
H

Heath P. Dillon

Hi,

I am trying build a form that has two list boxes, that allows the user to
move items from one to the other. Like when you have one list box full of
options, and you select the ones you want, and move them to the other
listbox.

to move items back or forth from one list box to the other I simply tried to
loop through the selected items of the listbox control. I then wanted to
remove the items from the listbox so that the user can not add again.

the problem is when I do a remove from the items collection of the list box,
I get the following error.

List that this enumerator is bound to has been modified. An enumerator can
only be used if the list does not change.

How do i remove the selected items from the listbox ??
 
C

Cor Ligthert[MVP]

Dillon,

As you use a listbox databinded, then you can only remove something from
that listbox by removing it from where it shows its items from.

Otherwise, you have to do it unbound.

Cor
 
J

Jack Jackson

Hi,

I am trying build a form that has two list boxes, that allows the user to
move items from one to the other. Like when you have one list box full of
options, and you select the ones you want, and move them to the other
listbox.

to move items back or forth from one list box to the other I simply tried to
loop through the selected items of the listbox control. I then wanted to
remove the items from the listbox so that the user can not add again.

the problem is when I do a remove from the items collection of the list box,
I get the following error.

List that this enumerator is bound to has been modified. An enumerator can
only be used if the list does not change.

How do i remove the selected items from the listbox ??

It would help if you had posted some code.

My guess is that you have a collection that you are traversing with a
For Each, which uses an Enumerator, which does not allow the list to
be changed while it is being traversed.

Use a For loop with an index instead, and don't forget to run it
backwards (from the end to the beginning), so that you don't have
problems when you remove an item.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top