Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
SelectedItems Property
Collapse the table of content
Expand the table of content

ListBox.SelectedItems Property

Gets the currently selected items.

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

[BindableAttribute(true)]
public IList SelectedItems { get; }

Property Value

Type: System.Collections.IList
Returns a collection of the currently selected items.

Identifier field

SelectedItemsProperty

Metadata properties set to true

None

ExceptionCondition
InvalidOperationException

The SelectionMode property is set to Single.

This property is meant to be used when SelectionMode does not equal Single. If the selection mode is Single the correct property to use is SelectedItem.

The following example shows how to use the SelectedItems property to determine whether a list box has any selected items.

private void SelectedItems(object sender, RoutedEventArgs e)
{
    if (lb.SelectedItem != null)
    {
        label1.Content = "Has " + (lb.SelectedItems.Count.ToString()) + " item(s) selected.";
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft