The data-grid context of a grid always exists; however, detail contexts are created and exist only when they are expanded and will be destroyed when a detail is collapsed. A data-grid context's HasDetails property can be queried to determine if it has details; however, it does not indicate whether the details are expanded and consequently have a context. To know if the details of a specific data item are expanded and therefore have a context, the AreDetailsExpanded method can be used.
Example
All examples in this topic assume that the grid is bound to the Employees table of the Northwind database, unless stated otherwise.
The following example demonstrates how to provide a default detail configuration that will be applied to all details in a grid and any descendant details for which an explicit detail configuration has not been provided.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