# C1.WPF.Grid.FlexGrid.CollapseGroups

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_WPF_Grid_FlexGrid_CollapseGroups_" data-uid="C1.WPF.Grid.FlexGrid.CollapseGroups*">CollapseGroups Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_WPF_Grid_FlexGrid_CollapseGroups_" data-uid="C1.WPF.Grid.FlexGrid.CollapseGroups*"></a>
<h4 id="C1_WPF_Grid_FlexGrid_CollapseGroups_System_Int32_" data-uid="C1.WPF.Grid.FlexGrid.CollapseGroups(System.Int32)">CollapseGroups(int)</h4>
<div class="markdown level1 summary"><p>Collapses the groups.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public void CollapseGroups(int level = 0)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub CollapseGroups(Optional level As Integer = 0)</code></pre>
</div>
<h5 class="parameters">Parameters</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Name</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">level</span></td>
      <td><p>Grouping level to show.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_WPF_Grid_FlexGrid_CollapseGroups_System_Int32__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>When the grid is bound to a grouped data source, it automatically
adds group rows above each group. Individual group rows can be collapsed
or expanded using the <a class="xref" href="C1.WPF.Grid.GridGroupRow.IsCollapsed.html#C1_WPF_Grid_GridGroupRow_IsCollapsed">IsCollapsed</a> property.</p>
<p>This method allows the caller to expand or collapse the entire 
outline to a given level.</p>
<p>For example, if the grid is bound to a data source with <b>three</b>
group descriptors, then <b>CollapseGroups(0)</b> would collapse all 
top-level group rows, showing only the first level of the grouping outline. 
<b>CollapseGroups(2)</b> would show all the group rows, and no data
rows. <b>CollapseGroups(3)</b> would show all rows (groups and
detail).</p>
<example>
The code below creates data source with three levels of grouping, then
shows the first two levels of the grouping outline:
<pre><code class="lang-csharp">// create grouped data source
var view = new C1DataCollection(dataList);
var gd = view.GroupDescriptions;
await view.GroupAsync("Country", "City", "Customer");
<p>// assign data source to grid
_flex.ItemsSource = view;</p>
<p>// collapse grouping outline to level 1
// (show country and city groups, hide customer groups and all detail rows)
_flex.CollapseGroups(1);</p>
<p>// expand grouping outline show all detail
_flex.CollapseGroups(gd.Count);</p>
<p>// collapse grouping outline to show all group rows and no detail
_flex.CollapseGroups(gd.Count - 1);</p></code></pre>
</example>
</div>
</div>
