We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Always keep one selected row


Xamarin Forms + SyncFusion Grid, Version, The tests are on UWP application

I am adding / updating / deleting rows of grid using source code, updating the grid itemsource in the viewmodel

After I add new row to the Grid, I select the new row as selected, this works ok
After I delete a row I want that the row after the deleted row will be selected, and if it was the last I want the row before deleted row to be selected, how can I do it ?

I have found that there is a problem setting SelectedIndex to the next or previous deleted row, only if I first set the SelectedIndex to other row (not near to the deleted row) and than set SelectedIndex to the required row, it works, any idea why ?

BTW - The same problem appear on screen too, when trying to select the row with the mouse, I first need to select other row and than select the row that is now in the place of the deleted row.

Am I doing something wrong ?


1 Reply

AN Ashok N Syncfusion Team August 30, 2017 07:17 PM UTC

Hi Yossef, 
Thanks for contacting Syncfusion support. 
You can achieve your requirement with help of SfDataGrid.SelectedIndex property and dataGrid.SelectionController.RefreshSelection method. Please refer the below code example, 
private void Select_Clicked(object sender, EventArgs e) 
    int selectedindex = dataGrid.SelectedIndex; 
    if(selectedindex == viewModel.OrdersInfo.Count) 
        viewModel.OrdersInfo.RemoveAt(viewModel.OrdersInfo.Count - 1); 
        dataGrid.SelectedIndex = selectedindex - 1; 
        viewModel.OrdersInfo.RemoveAt(selectedindex - 1); 
        dataGrid.SelectedIndex = selectedindex ; 

Live Chat Icon For mobile
Up arrow icon