Solved

removing items of a listbox dinamically

Posted on 2014-12-17
2
131 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

791 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