?
Solved

removing items of a listbox dinamically

Posted on 2014-12-17
2
Medium Priority
?
143 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
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 …
Introduction to Processes

752 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