ListView.SelectedItems Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the items that are selected in the control.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[<BrowsableAttribute(false)>]
member SelectedItems : ListView.SelectedListViewItemCollection with get

Property Value

Type: System.Windows.Forms.ListView.SelectedListViewItemCollection

A ListView.SelectedListViewItemCollection that contains the items that are selected in the control. If no items are currently selected, an empty ListView.SelectedListViewItemCollection is returned.

The SelectedItems property will not contain any items if the property is accessed before the ListView handle is created, which typically occurs when ListView is initially loaded for display in the form. You can check to see if the handle is created with the IsHandleCreated property. When the MultiSelect property is set to true, this property returns a collection containing the items that are selected in the ListView. For a single-selection ListView, this property returns a collection containing the only selected item in the ListView. For more information on the tasks that can be performed with the items in the collection, see ListView.SelectedListViewItemCollection.

If you want to obtain a collection of the index positions within the ListView.ListViewItemCollection of the items that are selected in the ListView control, instead of the items that are selected, use the SelectedIndices property.

The following code example demonstrates using the SelectedItems, SelectedIndexChanged event, and HeaderStyle members and the ListView.SelectedListViewItemCollection class. To run this example, paste the following code into a form that contains a ListView object named ListView1 and a TextBox named TextBox1. Call the InitializeListView method from the form's constructor or Load method. This example requires the event handler is correctly associated with the SelectedIndexChanged event

No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show: