# C1.WPF.FlexGrid.C1FlexGrid.CollapseGroupsToLevel

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_WPF_FlexGrid_C1FlexGrid_CollapseGroupsToLevel_" data-uid="C1.WPF.FlexGrid.C1FlexGrid.CollapseGroupsToLevel*">CollapseGroupsToLevel Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_WPF_FlexGrid_C1FlexGrid_CollapseGroupsToLevel_" data-uid="C1.WPF.FlexGrid.C1FlexGrid.CollapseGroupsToLevel*"></a>
<h4 id="C1_WPF_FlexGrid_C1FlexGrid_CollapseGroupsToLevel_System_Int32_" data-uid="C1.WPF.FlexGrid.C1FlexGrid.CollapseGroupsToLevel(System.Int32)">CollapseGroupsToLevel(int)</h4>
<div class="markdown level1 summary"><p>Collapses all the group rows to a given level.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public void CollapseGroupsToLevel(int level)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Sub CollapseGroupsToLevel(level As Integer)</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_FlexGrid_C1FlexGrid_CollapseGroupsToLevel_System_Int32__remarks">Remarks</h5>
<div class="markdown level1 remarks"><pre><code>&lt;p&gt;When the grid is bound to a grouped data source, it automatically
</code></pre>
<p>adds group rows above each group. Individual group rows can be collapsed
or expanded using the <a class="xref" href="C1.WPF.FlexGrid.GroupRow.IsCollapsed.html#C1_WPF_FlexGrid_GroupRow_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>CollapseGroupsToLevel(0)</b> would collapse all
top-level group rows, showing only the first level of the grouping outline.
<b>CollapseGroupsToLevel(2)</b> would show all the group rows, and no data
rows. <b>CollapseGroupsToLevel(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 PagedCollectionView(dataList);
var gd = view.GroupDescriptions;
gd.Add(new PropertyGroupDescription("Country"));
gd.Add(new PropertyGroupDescription("City"));
gd.Add(new PropertyGroupDescription("Customer"));

// assign data source to grid
_flex.ItemsSource = view;

// collapse grouping outline to level 1
// (show country and city groups, hide customer groups and all detail rows)
_flex.CollapseGroupsToLevel(1);

// expand grouping outline show all detail
_flex.CollapseGroupsToLevel(gd.Count);

// collapse grouping outline to show all group rows and no detail
_flex.CollapseGroupsToLevel(gd.Count - 1);</code></pre></example>
</div>
</div>
