Solved

ListBox item removal issue

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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