RowIndex in databound SfDataGrid

Hello,
is there a way how to get RowIndex of selected row in databound SfDataGrid? I need to get updated RowIndex when user changes sorting/filtering in the grid.
It would be nice if I could bind it directly to the row's model object.

Thank you for any advice

Ondřej Svoboda

1 Reply

JG Jai Ganesh S Syncfusion Team May 25, 2018 10:51 AM UTC

Hi Ondrej, 
 
You can achieve your requirement to get the Selected Row index when sorting /filtering by using the below code, 
 
private void GetSelectedRowIndex() 
{ 
    this.Dispatcher.BeginInvoke(new Action(() => 
    { 
        var selectedIndex = this.AssociatedObject.SelectedIndex; 
 
        if (selectedIndex >= 0) 
        { 
            var rowIndex = this.AssociatedObject.ResolveToRowIndex(selectedIndex); 
 
            var dataContext = this.AssociatedObject.DataContext as ViewModel; 
            dataContext.RowIndex = rowIndex; 
        } 
    })); 
} 
 
 
In the above sample, we have displayed the Selected row index value in TextBlock while sorting/filtering and SelectionChanging. 
 
Regards, 
Jai Ganesh S 
 
 


Loader.
Up arrow icon