467,135 Members | 1,195 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,135 developers. It's quick & easy.

listbox woes

hey all,

i have a listbox on my .aspx page and when i highlight an item in the
listbox should i just be able to loop thru the items collection of the
listbox and delete what is selected? it's not letting me do that for some
reason i keep getting an error saying:
Collection was modified; enumeration operation may not execute.

what's the best way to do the delete?

thanks,
rodchar
May 2 '06 #1
  • viewed: 966
Share:
2 Replies
You can't delete items from the collection that you are looping through.
Get the collection of selected items and use the ToArray method to get
them in an array. Loop through the array and remove each item from the
collection.

rodchar wrote:
hey all,

i have a listbox on my .aspx page and when i highlight an item in the
listbox should i just be able to loop thru the items collection of the
listbox and delete what is selected? it's not letting me do that for some
reason i keep getting an error saying:
Collection was modified; enumeration operation may not execute.

what's the best way to do the delete?

thanks,
rodchar

May 2 '06 #2
thank you.
"Göran Andersson" wrote:
You can't delete items from the collection that you are looping through.
Get the collection of selected items and use the ToArray method to get
them in an array. Loop through the array and remove each item from the
collection.

rodchar wrote:
hey all,

i have a listbox on my .aspx page and when i highlight an item in the
listbox should i just be able to loop thru the items collection of the
listbox and delete what is selected? it's not letting me do that for some
reason i keep getting an error saying:
Collection was modified; enumeration operation may not execute.

what's the best way to do the delete?

thanks,
rodchar

May 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by amber | last post: by
3 posts views Thread by Paul T. Rong | last post: by
8 posts views Thread by Oddball | last post: by
6 posts views Thread by Chris Leuty | last post: by
7 posts views Thread by Dave | last post: by
reply views Thread by John Dann | last post: by
3 posts views Thread by Ali Chambers | last post: by
1 post views Thread by Jason L. Froebe | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.