The ListBox..::.ObjectCollection class stores the items displayed in the ListBox. There are two other collections defined within the ListBox class that enable you to determine what items are selected within this collection. The ListBox..::.SelectedObjectCollection class provides properties and methods for determining what items are selected within the ListBox..::.ObjectCollection, while the ListBox..::.SelectedIndexCollection class enables you to determine what indexes within the ListBox..::.ObjectCollection are selected.
There are a number of ways to add items to the collection. The Add method provides the ability to add a single object to the collection. To add a number of objects to the collection, you create an array of items and assign it to the AddRange method. If you want to insert an object at a specific location within the collection, you can use the Insert method. To remove items, you can use either the Remove method or the RemoveAt method if you know where the item is located within the collection. The Clear method enables you to remove all items from the collection instead of using the Remove method to remove a single item at a time.
You can also manipulate the items of a ListBox by using the DataSource property. If you use the DataSource property to add items to a ListBox, you can view the items in the ListBox using the Items property but you cannot add or remove items from the list using the methods of the ListBox..::.ObjectCollection.
In addition to methods and properties for adding and removing items, the ListBox..::.ObjectCollection also provides methods to find items within the collection. The Contains method enables you to determine whether an object is a member of the collection. Once you know that the item is located within the collection, you can use the IndexOf method to determine where the item is located within the collection.