Solved

ListBox item removal issue

Posted on 2007-03-21
2
240 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now