Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Selector.SelectedItem Property

Gets or sets the first item in the current selection or returns null if the selection is empty.

Namespace: System.Windows.Controls.Primitives
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[BindableAttribute(true)] 
public Object SelectedItem { get; set; }
/** @property */
public Object get_SelectedItem ()

/** @property */
public void set_SelectedItem (Object value)

public function get SelectedItem () : Object

public function set SelectedItem (value : Object)

<object>
  <object.SelectedItem>
    <Object .../>
  </object.SelectedItem>
</object>

Property Value

The first item in the current selection or a null reference (Nothing in Visual Basic) if the selection is empty.

Identifier Field

SelectedItemProperty

Metadata Flags

None

If a Selector supports selecting a single item, the SelectedItem property returns the selected item. If a Selector supports multiple selections, SelectedItem returns the item that the user selected first.

Setting SelectedItem in a Selector that supports multiple selections clears existing selected items and sets the selection to the item specified.

void PrintText(object sender, SelectionChangedEventArgs args)
{
    ListBoxItem lbi = ((sender as ListBox).SelectedItem as ListBoxItem);
    tb.Text = "   You selected " + lbi.Content.ToString() + ".";
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft