Link to home
Start Free TrialLog in
Avatar of rowmark
rowmark

asked on

ListBox item removal issue

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
ASKER CERTIFIED SOLUTION
Avatar of mmarinov
mmarinov

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ethoths
ethoths

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.