Xceed Toolkit Plus for WPF v4.6 Documentation
SelectedIndex Property
Example 


Xceed.Wpf.DataGrid Assembly > Xceed.Wpf.DataGrid Namespace > DataGridControl Class : SelectedIndex Property

Gets or sets the index of the currently selected data item.

Syntax
'Declaration
 
Public Property SelectedIndex As Integer
'Usage
 
Dim instance As DataGridControl
Dim value As Integer
 
instance.SelectedIndex = value
 
value = instance.SelectedIndex
public int SelectedIndex {get; set;}

Property Value

The index of the currently selected data item. If no data item is selected, -1. By default, -1.
Remarks

The SelectedItems, SelectedItem, and SelectedIndex properties represent data items and not DataRows.

In the case where more than 1 data item is selected in a grid, the SelectedItem property will return the first data item in the SelectedItems collection and the SelectedIndex property will return the index of this same item.

Example

The following example demonstrates how to provide value-changed handlers for the SelectedItem and SelectedIndex dependency properties in order to be notified when their value changes (see Example 1).

The SelectedItems property is also a dependency property; however, using a value-changed handler will not function in this case since the values of the collection are modified and not the collection itself. Although the SelectedItems property is exposed as an IList it is actually an ObservableCollection; therefore, in order to be notified when its content (i.e., the items that are selected) changes, it can be cast as an INotifyCollectionChanged and subscribe to its CollectionChanged event (see Example 2).

Example 1
Dim selectedItemDescriptor As DependencyPropertyDescriptor = DependencyPropertyDescriptor.FromProperty( DataGridControl.SelectedItemProperty, GetType( DataGridControl ) )
selectedItemDescriptor.AddValueChanged( this.EmployeesGrid, this.SelectedItemChanged )
The following example demonstrates how to provide value-changed handlers for the SelectedItem and SelectedIndex dependency properties in order to be notified when their value changes.
Example 1
DependencyPropertyDescriptor selectedItemDescriptor = DependencyPropertyDescriptor.FromProperty( DataGridControl.SelectedItemProperty, typeof( DataGridControl ) );
selectedItemDescriptor.AddValueChanged( this.EmployeesGrid, this.SelectedItemChanged );
Example 2
AddHandler CType( Me.EmployeesGrid.SelectedItems, INotifyCollectionChanged ).CollectionChanged, AddressOf Me.Window1_CollectionChanged
Example 2
( ( INotifyCollectionChanged )this.EmployeesGrid.SelectedItems ).CollectionChanged += new NotifyCollectionChangedEventHandler( Window1_CollectionChanged );
Requirements

Target Platforms: Windows 11, Windows 10, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

DataGridControl Class
DataGridControl Members