The specified CollectionViewGroup is not part of the current context.
Remarks
The state of child groups will not be affected if their parent is collapsed.
Example
All examples in this topic assume that the grid is bound to the Orders table of the Northwind database, unless stated otherwise.
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.
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
The following provides the implementation for the CollapseCurrentGroup method.
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