Link to home
Start Free TrialLog in
Avatar of Denis Orozco
Denis OrozcoFlag for United States of America

asked on

removing items of a listbox dinamically

Hi there,
I have a windows form that has a listbox that on a event it loads items to it.  After user do something or change the tab or screen and comes back to the screen I have a line of code that reads as follows:
 If rlcExportPrevious.Items.Count > 0 Then
                        rlcExportPrevious.Items.Clear()
End If

Open in new window

after the second time around where there is data on the listbox I get an error saying "Object reference not set to an instance of an object." so in my effort to trying to solve the issue I have added a loop to remove items like this:
   While rlcExportPrevious.Items.Count > 0
                            rlcExportPrevious.Items.RemoveAt(rlcExportPrevious.Items.Count - 1)
   End While

Open in new window

this works until I get to the last record and throws the same error. If I use the word new as it suggests I lose the event SelectedIndexChanged and I need to keep that functionality. How do I solve my issue?
Thanks for your input
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

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 Denis Orozco

ASKER

You were right i was using a Telerik control that did not allow to do what i need