By default, DetailsViewDataGrid expanded state is maintain when group of WinForms DataGrid (SfDataGrid) is collapsed. If we need to collapse the DetailsViewDataGrid when group of DataGrid is collapsed, this can be achieved by disabling the IsExpanded of DetailsViewDataGrid in SfDataGrid.GroupExpanding event.
this.sfDataGrid1.GroupExpanding += SfDataGrid1_GroupExpanding;
private void SfDataGrid1_GroupExpanding(object sender, Syncfusion.WinForms.DataGrid.Events.GroupChangingEventArgs e)
{
CollapseAllNestedGrids(e.Group);
}
void CollapseAllNestedGrids(Group group)
{
if (group != null && group.Records != null)
{
foreach (var item in group.Records)
{
if (item.IsGroups == false)
item.IsExpanded = false;
}
}
if (group.Groups != null)
{
foreach (var item in group.Groups)
CollapseAllNestedGrids(item);
}
}Visual Studio 2015 and above versions