Xceed DataGrid for WPF v7.2 Documentation
Retrieving Child Contexts
Welcome to Xceed DataGrid, Editors, and 3D Views for WPF v7.2 > Xceed DataGrid for WPF > Code Snippets > Retrieving Child Contexts

The following example demonstrates how to retrieve the child contexts of the master data items and collapse any expanded details using the CollapseDetail method.

XAML
Copy Code
<Grid>

  <Grid.Resources>

     <xcdg:DataGridCollectionViewSource x:Key="cvs_employees"

                                        Source="{Binding Source={x:Static Application.Current},

                                                         Path=Employees}"/>

 

  </Grid.Resources>

 

  <DockPanel>

     <Button Content="Collapse All Details"

             Click="Button_Click"

             DockPanel.Dock="Top"/>

     <xcdg:DataGridControl x:Name="EmployeesGrid"

                           ItemsSource="{Binding Source={StaticResource cvs_employees}}"

                           ItemsSourceName="Order Information"

                           AutoCreateDetailConfigurations="True"/>

  </DockPanel>

</Grid>

The next example provides the implementation of the button's Click event.

VB.NET
Copy Code
Private Sub Button_Click( ByVal sender As Object, ByVal e As RoutedEventArgs )

  Dim childContexts As New List( Of DataGridContext)( Me.EmployeesGrid.GetChildContexts() )

  Dim context As DataGridContext

  For Each context In childContexts

    context.ParentDataGridContext.CollapseDetails( context.ParentItem )

  Next context

End Sub
C#
Copy Code
private void Button_Click( object sender, RoutedEventArgs e )

{

 List<DataGridContext> childContexts = new List<DataGridContext>( this.EmployeesGrid.GetChildContexts() );

 foreach( DataGridContext context in childContexts )

 {

   context.ParentDataGridContext.CollapseDetails( context.ParentItem );

 }     

}