How to retain selected records in details view grid?

I am using SfDataGrid in a master-detail scenario. When the user expands a row, the grid is with the child records is displayed. The details grid definition is added to the master grid upon startup using Grid.DetailsViewDefinitions.Add(NewDetailViewDef), with the NewDetailViewDef having the RelationalColumn set to a (name of the) list of objects from the parent object.

  Order
    Number
    (other)
    ItemList[]

  Item
    SKU
    (other)

Binding of the details grid works properly. I added a selection column to the details grid, but the selection is lost when I open another master row. I need to be able to retain the row selection in the details grid in subsequent master row open/close operations, plus be able to get the selections for each of the detail grids when a "Process" button is clicked. I've been able to achieve this with a simple "global" list of objects similar to the Order class above--this class holds the key of the master and the key keys of the details grid selected items. The maintenance of the list works fine. My issue is being able to re-select the rows when the master row is opened again.

I have tried the following events:
  • OrdersGrid_DetailsViewExpanded
  • ItemsGrid_QueryRowStyle
  • ItemsGrid_DataSourceChanged
However, none of these events provide a valid bound details grid in order to re-select the items.

Am I missing something? Is there a better, cleaner way to do this?

1 Reply 1 reply marked as answer

DM Dhanasekar Mohanraj Syncfusion Team September 15, 2020 10:11 AM UTC

Hi Kevin Swanner, 

Thank you for using Syncfusion controls. 
Based on the provided information, we suspect that you did not set the SelectionMode for parent grid. If you need to select multiple row you should set SelectionMode as multiple for parent grid. 
Code Snippet C#: 
this.sfDataGrid1.SelectionMode = Syncfusion.WinForms.DataGrid.Enums.GridSelectionMode.Multiple; 


We have also prepared sample based on your requirement, please find the sample by the following link.
Sample Link: 
Please let us know, if you require further assistance from us.  
Regards,
Dhanasekar Mohanraj 


Marked as answer
Loader.
Up arrow icon