Newbie Question

  • Thread starter Thread starter RD
  • Start date Start date
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.
 
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
 
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
 
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.
 
Back
Top