Solved

removing items of a listbox dinamically

Posted on 2014-12-17
2
119 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
Comment Utility
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
Comment Utility
You were right i was using a Telerik control that did not allow to do what i need
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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 …
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…

743 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

10 Experts available now in Live!

Get 1:1 Help Now