Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2004, 09:34 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default Mover Box

I am working on what I have come to call a "Mover Box". That is, two listboxes with buttons between them to allow the user to move selections from one box to the other.

The process has 2 steps:
1. Taking the selection(s) made in one box and adding them to the other.
2. Removing them from the originating listbox.

Step 1 went smoothly with this code:
Code:
Dim li As ListItem
For Each li In lbOrigin.Items
    If li.Selected Then
        lbDestination.Items.Add(New ListItem(li.Text, li.Value))
    End If
Next
However, I thought that step 2 would be as straightforward with this code:
Code:
For Each li In lbOrigin.Items
    If li.Selected Then
        lbOrigin.Items.Remove(li)
    End If
Next
When I run this code, step 2 generates the error, "Collection was modified; enumeration operation may not execute."

I'm having trouble finding a way around this. I have tried a few avenues, but all were dead ends.

Any ideas on how I can remove these items successfully?

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old February 20th, 2004, 10:22 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, file this under "I shouldn't have over complicated this" or under "Duh".

The solution is this. I was thinking that I was dealing with a collection, and that the SelectedItem property was only a single value - likely the first or last Item that I clicked on.

Well, I was only partly wrong. All I needed was this:
Code:
lbOrigin.Items.Remove(lbAvailable.SelectedItem)
That takes care of the error, but only the first item selected is removed.



-Colonel

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Grab Values From List Box into Text Box phungleon VB How-To 2 June 19th, 2008 10:33 PM
Count in combo box(display results in text box) mboyisis Access 4 April 4th, 2008 07:08 AM
select box/List box alphabetic sort sasidhar79 Javascript How-To 3 November 10th, 2004 03:04 AM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM
Search using drop down list box and a text box tcasp Classic ASP Basics 1 July 31st, 2003 02:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.