Newbie Question


R

RD

Got a list box that I filled in with the add method. I want to clear it all
before i put new info in it with the add method again

In the
_SelectedIndexChanged event of another list box I wrote

mylbtoclear.objectCollection.clear that gives me REference to a non-shared
member requires an object reference.

Exactly what to do to clear a listbox of all the data it contains. I took
this out of MS docs but I missed something <GGG>

Thanks for any help.
 
Ad

Advertisements

A

Armin Zingler

RD said:
Got a list box that I filled in with the add method. I want to clear
it all before i put new info in it with the add method again

In the
_SelectedIndexChanged event of another list box I wrote

mylbtoclear.objectCollection.clear that gives me REference to a
non-shared member requires an object reference.

Exactly what to do to clear a listbox of all the data it contains. I
took this out of MS docs but I missed something <GGG>

Thanks for any help.
mylbtoclear.Items.Clear
 
P

Prashant Bajaj

Hi,
You can do this by using the 'Items' Property of ListBox
(Property Value : An ListBox.ObjectCollection representing
the items in the ListBox)

This property enables you to obtain a reference to the
list of items that are currently stored in the ListBox.
With this reference, you can add items, remove items, and
obtain a count of the items in the collection.

In your case this code will work : mylbtoclear.Items.Clear

Regards,

Prashant Bajaj
 
Ad

Advertisements

H

Herfried K. Wagner [MVP]

RD said:
Got a list box that I filled in with the add method. I want to
clear it all before i put new info in it with the add method again

In the
_SelectedIndexChanged event of another list box I wrote

mylbtoclear.objectCollection.clear that gives me REference to
a non-shared member requires an object reference.
Use 'MyListBoxToClear.Items.Clear()' instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Newbie Question 2
Newby question 4
Newbie question 19
Newbie Question 5
Newbie question 1
Newbie question 21
Newbie Questions 1
NEWBIE question 5

Top