Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How To Clear a Listbox Using an ArrayList DataSource?

3 views
Skip to first unread message

Slagert

unread,
Aug 17, 2007, 3:16:21 PM8/17/07
to
How do I clear a Listbox that uses an ArrayList for its DataSource?

If I try MyListBox.Items.Clear I get an exception telling me I can't change
the listbox's ItemCollection if the DataSource is set.

If I try MyArrayList.Clear I see that the array is cleared but the listbox
is not. If I then add new items to the array they do not show in the
listbox.

So how do I clear a listbox if the datasource is set?

-Andy


Slagert

unread,
Aug 24, 2007, 12:31:16 PM8/24/07
to
Ok, I'll answer this myself since nobody seems to be listening here...

To empty a Delphi .Net listbox that uses an array for a data source just set
the listbox's datasource property to nil. For instance if your listbox is
named MyListbox you can use the following code to remove the items from the
listbox.

MyListbox .DataSource := nil;

There it is, now we have the answer.

-Andy


Marc Rohloff [TeamB]

unread,
Aug 24, 2007, 1:43:00 PM8/24/07
to

You could also set it to an empty array if it makes your code simpler.

--
Marc Rohloff [TeamB]
marc -at- marc rohloff -dot- com

0 new messages