473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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
2 1105
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
3
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name...
8
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
0
by: John Dann | last post by:
I had a listbox that allows reordering of listed items using the mouse to drag and drop. In the DragDrop event handler, the key instructions are: MyListBox..Items.RemoveAt(PreMoveIndex)...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
1
by: Jason L. Froebe | last post by:
Visual C# 2003, with latest .NET 1.1 SDK patch. I've created a simple test app containing a list box and a button. When the button is clicked on, it adds three items to the listBox and...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.