DataGrid.CollapseRowGroup Method
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Collapses data grid row groups.
Namespace: System.Windows.Controls
Assembly: System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)
Syntax
'Declaration
Public Sub CollapseRowGroup ( _
collectionViewGroup As CollectionViewGroup, _
collapseAllSubgroups As Boolean _
)
public void CollapseRowGroup(
CollectionViewGroup collectionViewGroup,
bool collapseAllSubgroups
)
Parameters
- collectionViewGroup
Type: System.Windows.Data.CollectionViewGroup
The row group to collapse.
- collapseAllSubgroups
Type: System.Boolean
true to collapse all subgroups of the row group; otherwise, false.
Remarks
You can call this method to programmatically collapse row groups in a DataGrid control that contains grouped data. You can use the GetGroupFromItem method to get the particular group that a specified item belongs to. Alternatively, you can iterate through the Groups collection to expand all row groups.
Examples
The following example demonstrates how to collapse all row groups in a DataGrid control. This example is part of a larger example available in the How to: Group, Sort, and Filter Data in the DataGrid Control topic.
Private Sub CollapseButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim pcv As PagedCollectionView = Me.dataGrid1.ItemsSource
Try
For Each group As CollectionViewGroup In pcv.Groups
dataGrid1.ScrollIntoView(group, Nothing)
dataGrid1.CollapseRowGroup(group, True)
Next
Catch ex As Exception
' Could not collapse group.
MessageBox.Show(ex.Message)
End Try
End Sub
private void CollapseButton_Click(object sender, RoutedEventArgs e)
{
PagedCollectionView pcv = dataGrid1.ItemsSource as PagedCollectionView;
try
{
foreach (CollectionViewGroup group in pcv.Groups)
{
dataGrid1.ScrollIntoView(group, null);
dataGrid1.CollapseRowGroup(group, true);
}
}
catch (Exception ex)
{
// Could not collapse group.
MessageBox.Show(ex.Message);
}
}
Version Information
Silverlight
Supported in: 5, 4, 3
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
See Also