# C1.Win.FlexGrid.C1FlexGrid.GetMergedRange

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_Win_FlexGrid_C1FlexGrid_GetMergedRange_" data-uid="C1.Win.FlexGrid.C1FlexGrid.GetMergedRange*">GetMergedRange Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_Win_FlexGrid_C1FlexGrid_GetMergedRange_" data-uid="C1.Win.FlexGrid.C1FlexGrid.GetMergedRange*"></a>
<h4 id="C1_Win_FlexGrid_C1FlexGrid_GetMergedRange_System_Int32_System_Int32_System_Boolean_" data-uid="C1.Win.FlexGrid.C1FlexGrid.GetMergedRange(System.Int32,System.Int32,System.Boolean)">GetMergedRange(int, int, bool)</h4>
<div class="markdown level1 summary"><p>Returns the merged range of cells that includes a given cell.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public virtual CellRange GetMergedRange(int row, int col, bool clip)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Overridable Function GetMergedRange(row As Integer, col As Integer, clip As Boolean) As CellRange</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">row</span></td>
      <td><p>Row index.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">col</span></td>
      <td><p>Column index.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></td>
      <td><span class="parametername">clip</span></td>
      <td><p>Whether the range should be clipped to the visible area of the grid.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.Win.FlexGrid.CellRange.html">CellRange</a></td>
      <td><p>A <a class="xref" href="C1.Win.FlexGrid.CellRange.html">CellRange</a> object that contains the given cell.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Win_FlexGrid_C1FlexGrid_GetMergedRange_System_Int32_System_Int32_System_Boolean__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>Cell merging is controlled by the <a class="xref" href="C1.Win.FlexGrid.C1FlexGrid.AllowMerging.html#C1_Win_FlexGrid_C1FlexGrid_AllowMerging">AllowMerging</a> property.
The <a class="xref" href="C1.Win.FlexGrid.C1FlexGrid.GetMergedRange.html#C1_Win_FlexGrid_C1FlexGrid_GetMergedRange_System_Int32_System_Int32_System_Boolean_">GetMergedRange(int, int, bool)</a> method allows you to determine whether a cell is 
merged with adjacent cells.</p>
<p>You can override the <a class="xref" href="C1.Win.FlexGrid.C1FlexGrid.GetMergedRange.html#C1_Win_FlexGrid_C1FlexGrid_GetMergedRange_System_Int32_System_Int32_System_Boolean_">GetMergedRange(int, int, bool)</a> method to implement custom merging
logic. If you do this, make sure the merging method is consistent and efficient, since
it gets called frequently and affects the grid's appearance and behavior.</p>
</div>
<h5 id="C1_Win_FlexGrid_C1FlexGrid_GetMergedRange_System_Int32_System_Int32_System_Boolean__examples">Examples</h5>
<p>The code below checks the current cell after a selection to see if it is part
of a merged range:</p>
<pre><code class="lang-csharp">private void _flex_SelChange(object sender, System.EventArgs e)
{
  CellRange rg = this._flex.GetMergedRange(_flex.Row, _flex.Col, false);
  if (!rg.IsSingleCell)
  {
    Console.WriteLine("selection is merged: {0},{1}-{2},{3}",
    rg.TopRow, rg.LeftCol, rg.BottomRow, rg.RightCol);
  }
}</code></pre>
<p>The code below shows how you can override the <a class="xref" href="C1.Win.FlexGrid.C1FlexGrid.GetMergedRange.html#C1_Win_FlexGrid_C1FlexGrid_GetMergedRange_System_Int32_System_Int32_System_Boolean_">GetMergedRange(int, int, bool)</a> method
to provide custom merging:</p>
<pre><code class="lang-csharp">public class CustomMerge : C1FlexGrid
{
  public CustomMerge()
  {
    // allow free merging by default
    AllowMerging = AllowMergingEnum.Free;
    for (int r = 0; r &lt; Rows.Count; r++) Rows[r].AllowMerging = true;
    for (int c = 0; c &lt; Cols.Count; c++) Cols[c].AllowMerging = true;
  }
  override public CellRange GetMergedRange(int row, int col, bool clip)
  {
    // merge cells in range (1,1)-(3,3)
    if (row &gt;= 1 &amp;&amp; row &lt;= 3 &amp;&amp; col &gt;= 1 &amp;&amp; col &lt;= 3)
      return GetCellRange(1, 1, 3, 3);

    // don't merge anything else
    return GetCellRange(row, col);
  }
}</code></pre>



<a id="C1_Win_FlexGrid_C1FlexGrid_GetMergedRange_" data-uid="C1.Win.FlexGrid.C1FlexGrid.GetMergedRange*"></a>
<h4 id="C1_Win_FlexGrid_C1FlexGrid_GetMergedRange_System_Int32_System_Int32_" data-uid="C1.Win.FlexGrid.C1FlexGrid.GetMergedRange(System.Int32,System.Int32)">GetMergedRange(int, int)</h4>
<div class="markdown level1 summary"><p>Returns the merged range of cells that includes a given cell.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public CellRange GetMergedRange(int row, int col)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Function GetMergedRange(row As Integer, col As Integer) As CellRange</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">row</span></td>
      <td><p>Row index.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">col</span></td>
      <td><p>Column index.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 class="returns">Returns</h5>
<table class="table table-bordered table-condensed">
  <thead>
    <tr>
      <th>Type</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><a class="xref" href="C1.Win.FlexGrid.CellRange.html">CellRange</a></td>
      <td><p>A <a class="xref" href="C1.Win.FlexGrid.CellRange.html">CellRange</a> object that contains the given cell.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Win_FlexGrid_C1FlexGrid_GetMergedRange_System_Int32_System_Int32__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>This method returns the entire range, including invisible cells.</p>
</div>
</div>
