All examples in this topic assume that the grid is bound to the Orders or Employees table of the Northwind database, unless stated otherwise.
The following example demonstrates how to handle the PreviewMouseLeftButtonDown event on the GroupHeaderControl objects contained in the headers of the child groups to toggle the expansion state of child groups using the ToggleGroupExpansion method. The group whose state is to be toggled will be retrieved using the GetParentGroupFromItem method.The following code provides the implementation of the PreviewMouseLeftButtonDown event in which we will retrieve the item represented by the GroupHeaderControl (GroupHeaderFooterItem) using the GetItemFromContainer method, which will then be used to retrieve the parent group (GetParentGroupFromItem) whose state is to be toggled.The following code provides the implementation of the PreviewMouseLeftButtonDown event in which we will retrieve the item represented by the GroupHeaderControl (GroupHeaderFooterItem) using the GetItemFromContainer method, which will then be used to retrieve the parent group (GetParentGroupFromItem) whose state is to be toggled.The following example demonstrates how to retrieve the child contexts of the master data items and collapse any expanded details using the CollapseDetail method.The next example provides the implementation of the button's Click event.The next example provides the implementation of the button's Click event.
<Grid><Grid.Resources><xcdg:DataGridCollectionViewSourcex:Key="cvs_employees"Source="{Binding Source={x:Static Application.Current},
Path=Employees}"/></Grid.Resources><DockPanel><ButtonContent="Collapse All Details"Click="Button_Click"DockPanel.Dock="Top"/><xcdg:DataGridControlx:Name="EmployeesGrid"ItemsSource="{Binding Source={StaticResource cvs_employees}}"ItemsSourceName="Order Information"AutoCreateDetailConfigurations="True"/></DockPanel></Grid>
PrivateSub Button_Click( ByVal sender AsObject, ByVal e As RoutedEventArgs )
DataGridContext rootContext = DataGridControl.GetDataGridContext( this.EmployeesGrid );
Dim childContexts AsNew List( Of DataGridContext)( Me.EmployeesGrid.GetChildContexts() )
Dim context As DataGridContext
ForEach context In childContexts
context.ParentDataGridContext.CollapseDetails( context.ParentItem )
Next context
End Sub
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