# C1.WPF.FlexGrid.GridPanel.GetCellElement

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_WPF_FlexGrid_GridPanel_GetCellElement_" data-uid="C1.WPF.FlexGrid.GridPanel.GetCellElement*">GetCellElement Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_WPF_FlexGrid_GridPanel_GetCellElement_" data-uid="C1.WPF.FlexGrid.GridPanel.GetCellElement*"></a>
<h4 id="C1_WPF_FlexGrid_GridPanel_GetCellElement_C1_WPF_FlexGrid_CellRange_" data-uid="C1.WPF.FlexGrid.GridPanel.GetCellElement(C1.WPF.FlexGrid.CellRange)">GetCellElement(CellRange)</h4>
<div class="markdown level1 summary"><p>Gets the <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.frameworkelement">FrameworkElement</a> used to represent a cell on the panel.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public FrameworkElement GetCellElement(CellRange rng)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Function GetCellElement(rng As CellRange) As FrameworkElement</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="C1.WPF.FlexGrid.CellRange.html">CellRange</a></td>
      <td><span class="parametername">rng</span></td>
      <td><p><a class="xref" href="C1.WPF.FlexGrid.CellRange.html">CellRange</a> to locate.</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="https://learn.microsoft.com/dotnet/api/system.windows.frameworkelement">FrameworkElement</a></td>
      <td><p>A <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.frameworkelement">FrameworkElement</a> used to represent a cell on the panel.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_WPF_FlexGrid_GridPanel_GetCellElement_C1_WPF_FlexGrid_CellRange__remarks">Remarks</h5>
<div class="markdown level1 remarks"><pre><code>&lt;p&gt;The default class factory uses &lt;xref href=&quot;System.Windows.Controls.Border&quot; data-throw-if-not-resolved=&quot;false&quot;&gt;&lt;/xref&gt; elements to represent
</code></pre>
<p>all cells. The border is responsible for rendering the cell's background color and
the gridlines. The border contains the elements that represent the cell's actual
content. In most cases, the border child is a simple <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.controls.textblock">TextBlock</a> or
<a class="xref" href="https://learn.microsoft.com/dotnet/api/system.windows.controls.checkbox">CheckBox</a>element that displays the cell content. Cells that contain
text and graphics (e.g. sorted column headers and group rows) host a
<a class="xref" href="C1.WPF.FlexGrid.GridPanel.Grid.html#C1_WPF_FlexGrid_GridPanel_Grid">Grid</a> element that contains the text and graphics elements.</p>
<p>This method can be useful in cases where you want to customize a cell after it has
been created by the cell factory.</p>
<p>This method returns null if the requested range is not within the current view
(see the <a class="xref" href="C1.WPF.FlexGrid.C1FlexGrid.ViewRange.html#C1_WPF_FlexGrid_C1FlexGrid_ViewRange">ViewRange</a> property), or if the requested range does
not match exactly the range represented by the cell (if the range is merged for example).</p>
</div>
<h5 id="C1_WPF_FlexGrid_GridPanel_GetCellElement_C1_WPF_FlexGrid_CellRange__examples">Examples</h5>
<p>The code below turns the selected cells red:</p>
<pre><code class="lang-csharp">// loop through the cells in the current selection
foreach (var cell in _flex.Selection.Cells)
{
  // get element used to represent the cell
  var bdr = _flex.Cells.GetCellElement(cell) as Border;
  if (bdr != null)
  {
    // make it red
    bdr.Background = new SolidColorBrush(Colors.Red);
  }
}</code></pre>

</div>
