Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Selector.SelectedIndex Property

Gets or sets the index of the first item in the current selection or returns negative one (-1) 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

'Declaration
<BindableAttribute(True)> _
<LocalizabilityAttribute(LocalizationCategory.NeverLocalize)> _
Public Property SelectedIndex As Integer
'Usage
Dim instance As Selector
Dim value As Integer

value = instance.SelectedIndex

instance.SelectedIndex = value
/** @property */
public int get_SelectedIndex ()

/** @property */
public void set_SelectedIndex (int value)

public function get SelectedIndex () : int

public function set SelectedIndex (value : int)

<object SelectedIndex="int" .../>

Property Value

The index of first item in the current selection. The default value is negative one (-1).

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

Setting SelectedIndex in a Selector that supports multiple selections clears existing selected items and sets the selection to the item specified by the index. SelectedIndex returns -1 if selection is empty.

If you set SelectedIndex to a value less that -1, an ArgumentException is thrown. If you set SelectedIndex to a value equal or greater than the number of child elements, the value is ignored.

The following example uses the SelectedIndex property to determine whether the item at index 0 is the first item in the selection.

if (lb.SelectedIndex == 0)
{
    Item.Content = "Index 0";
}

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
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.