Represents the collection containing the indexes to the selected items in a ListBox.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Thetype exposes the following members.
|Add||Adds the ListBox at the specified index location.|
|Clear||Removes all controls from the collection.|
|Contains||Determines whether the specified index is located within the collection.|
|CopyTo||Copies the entire collection into an existing array at a specified location within the array.|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetEnumerator||Returns an enumerator to use to iterate through the selected indexes collection.|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|IndexOf||Returns the index within the of the specified index from the ListBox.ObjectCollection of the ListBox.|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|Remove||Removes the specified control from the collection.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
|AsParallel()||Overloaded. Enables parallelization of a query. (Defined by ParallelEnumerable.)|
|AsParallel()||Overloaded. (Defined by ParallelEnumerable.)|
|AsQueryable()||Overloaded. Converts an IEnumerable to an IQueryable. (Defined by Queryable.)|
|AsQueryable()||Overloaded. (Defined by Queryable.)|
|Cast(TResult)()||Overloaded. Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)|
|Cast(TResult)()||Overloaded. (Defined by Enumerable.)|
|OfType(TResult)()||Overloaded. Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)|
|OfType(TResult)()||Overloaded. (Defined by Enumerable.)|
|ICollection.IsSynchronized||Infrastructure. For a description of this member, see ICollection.IsSynchronized.|
|ICollection.SyncRoot||Infrastructure. For a description of this member, see ICollection.SyncRoot.|
|IList.Add||Infrastructure. For a description of this member, see IList.Add.|
|IList.Clear||Infrastructure. For a description of this member, see IList.Clear.|
|IList.Contains||Infrastructure. For a description of this member, see IList.Contains.|
|IList.IndexOf||Infrastructure. For a description of this member, see IList.IndexOf.|
|IList.Insert||Infrastructure. For a description of this member, see IList.Insert.|
|IList.IsFixedSize||Infrastructure. For a description of this member, see IList.IsFixedSize.|
|IList.Item||Infrastructure. For a description of this member, see IList.Item.|
|IList.Remove||Infrastructure. For a description of this member, see IList.Remove.|
|IList.RemoveAt||Infrastructure. For a description of this member, see IList.RemoveAt.|
The class stores the indexes to the selected items in the ListBox. The indexes stored in the are index positions within the ListBox.ObjectCollection class. The ListBox.ObjectCollection class stores all items displayed in the ListBox.
Selection state within the ListBox
Based on the ListBox.ObjectCollection example in the previous table, the following table demonstrates how the would appear.
Index of selected item in ObjectCollection
You can use the properties and methods of this class to perform a variety of tasks with the collection. The Contains method enables you to determine whether an index position from the ListBox.ObjectCollection class is a member of the selected indexes stored in the . Once you know that the item is located within the collection, you can use the IndexOf method to determine where a specific index position within the ListBox.ObjectCollection for the ListBox is stored.
The following example demonstrates how to use the FindString method to search for all instances of the search text in the items of the ListBox. The example uses the version of the FindString method that enables you to specify a starting search index from which to do a continual search of all items in the ListBox. The example also demonstrates how to determine when the FindString method begins searching from the top of the list after it reaches the bottom of the list of items to prevent a recursive search. Once items are found in the ListBox, they are selected using the SetSelected method.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)