'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;}
Gets or sets the index of the currently selected data item.
'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;}
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.
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).
Dim selectedItemDescriptor As DependencyPropertyDescriptor = DependencyPropertyDescriptor.FromProperty( DataGridControl.SelectedItemProperty, GetType( DataGridControl ) ) selectedItemDescriptor.AddValueChanged( this.EmployeesGrid, this.SelectedItemChanged )
DependencyPropertyDescriptor selectedItemDescriptor = DependencyPropertyDescriptor.FromProperty( DataGridControl.SelectedItemProperty, typeof( DataGridControl ) ); selectedItemDescriptor.AddValueChanged( this.EmployeesGrid, this.SelectedItemChanged );
AddHandler CType( Me.EmployeesGrid.SelectedItems, INotifyCollectionChanged ).CollectionChanged, AddressOf Me.Window1_CollectionChanged
( ( INotifyCollectionChanged )this.EmployeesGrid.SelectedItems ).CollectionChanged += new NotifyCollectionChangedEventHandler( Window1_CollectionChanged );
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