Solved

removing items of a listbox dinamically

Posted on 2014-12-17
2
123 Views
Last Modified: 2014-12-23
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
0
Comment
Question by:COHFL
2 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 40505144
You need to post more code - your error is somewhere else.  

The following is enough to do what you want:
rlcExportPrevious.Items.Clear()

Open in new window

You do not even need to check if there are items in the list.
0
 

Author Closing Comment

by:COHFL
ID: 40515625
You were right i was using a Telerik control that did not allow to do what i need
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

895 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

11 Experts available now in Live!

Get 1:1 Help Now