Solved

ListBox item removal issue

Posted on 2007-03-21
2
244 Views
Last Modified: 2010-04-16
Hello Experts,

I have two Listboxes in my ASPX page. On page load  the first listbox(lballcolumns) lists all the items from the db after loading all items using the below code I am removing the items that all already in the  second Listbox(lbselected).

for (int i = lbselectedColumns.Items.Count-1; i >= 0; i--)
            {
                if (lbselectedColumns.Items[i].Selected)
                {
                    lballcolumns.Items.RemoveAt(i);
                }
            }

But somehow last item is not getting removed. For eg. if First Name is the last column in my dbtable, that is not getting removed. What may be the reason.

Please help
0
Comment
Question by:rowmark
2 Comments
 
LVL 28

Accepted Solution

by:
mmarinov earned 500 total points
ID: 18764282
Are you sure that
lballcolumns.Items.RemoveAt(0); will not remove it?
I think that the problem is in the indexing of the items

Martin
0
 
LVL 11

Expert Comment

by:ethoths
ID: 18764348
The problem could be that as you remove the items the value of lbselectedColumns.Items.Count is decreasing so you could infact just jump over items. Try doing a i-- inside the if clause.

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question