This documentation is archived and is not being maintained.

ListBox.SelectedItems Property

Gets the currently selected items. This is a dependency property.

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

[BindableAttribute(true)]
public IList SelectedItems { get; }
You cannot set this property in XAML.

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.";
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Show: