A CollectionViewGroup representing the parent group of the specified item. Can be a null reference (Nothing in Visual Basic) if the item is part of the context but does not have parent group.
Example
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 parent group of the current item using the GetParentGroupFromItem method so that it can be collapsed. The implementation for the CollapseCurrentGroup method is provided below.The following provides the implementation for the CollapseCurrentGroup method.The following provides the implementation for the CollapseCurrentGroup method.
PrivateSub CollapseCurrentGroup( ByVal sender AsObject, ByVal e As RoutedEventArgs )
Dim context As DataGridContext = Me.OrdersGrid.CurrentContext
DimgroupAs CollectionViewGroup = context.GetParentGroupFromItem( context.CurrentItem )
context.CollapseGroup( group )
End Sub
privatevoid CollapseCurrentGroup( object sender, RoutedEventArgs e )
{
DataGridContext context = this.OrdersGrid.CurrentContext;
CollectionViewGroup group = context.GetParentGroupFromItem( context.CurrentItem );
context.CollapseGroup( group );
}
Requirements
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