Export (0) Print
Expand All

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

Community Additions

ADD
Show:
© 2015 Microsoft