# C1.Win.FlexGrid.C1FlexGridBase.SetData

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_Win_FlexGrid_C1FlexGridBase_SetData_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.SetData*">SetData Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_Win_FlexGrid_C1FlexGridBase_SetData_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.SetData*"></a>
<h4 id="C1_Win_FlexGrid_C1FlexGridBase_SetData_System_Int32_System_Int32_System_Object_System_Boolean_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.SetData(System.Int32,System.Int32,System.Object,System.Boolean)">SetData(int, int, object, bool)</h4>
<div class="markdown level1 summary"><p>Assigns a value to a grid 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 bool SetData(int row, int col, object value, bool coerce)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Overridable Function SetData(row As Integer, col As Integer, value As Object, coerce As Boolean) As Boolean</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.object">object</a></td>
      <td><span class="parametername">value</span></td>
      <td><p>Value to assign to the cell.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></td>
      <td><span class="parametername">coerce</span></td>
      <td><p>Whether the value should be converted to the column's data type.</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.boolean">bool</a></td>
      <td><p>True if the value was assigned to the cell.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Win_FlexGrid_C1FlexGridBase_SetData_System_Int32_System_Int32_System_Object_System_Boolean__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>If <code class="paramref">coerce</code> is set to true and the value can't be converted into 
the proper data type, the grid will fire the <a class="xref" href="C1.Win.FlexGrid.C1FlexGridBase.GridError.html">GridError</a> event and the 
cell will retain its original value.</p>
<p>Using <a class="xref" href="C1.Win.FlexGrid.C1FlexGridBase.SetData.html#C1_Win_FlexGrid_C1FlexGridBase_SetData_System_Int32_System_Int32_System_Object_System_Boolean_">SetData(int, int, object, bool)</a> with <code class="paramref">coerce</code> set to true is equivalent 
to setting the grid's indexer. For example, the following lines of code are equivalent:</p>
<pre><code class="lang-csharp">flex.SetData(1, 1, "Hello", true);
flex[1, 1] = "Hello"; // same thing</code></pre>
</div>


<a id="C1_Win_FlexGrid_C1FlexGridBase_SetData_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.SetData*"></a>
<h4 id="C1_Win_FlexGrid_C1FlexGridBase_SetData_C1_Win_FlexGrid_CellRange_System_Object_System_Boolean_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.SetData(C1.Win.FlexGrid.CellRange,System.Object,System.Boolean)">SetData(CellRange, object, bool)</h4>
<div class="markdown level1 summary"><p>Assigns a value to a range of cells.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public virtual bool SetData(CellRange rg, object value, bool coerce)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Overridable Function SetData(rg As CellRange, value As Object, coerce As Boolean) As Boolean</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.Win.FlexGrid.CellRange.html">CellRange</a></td>
      <td><span class="parametername">rg</span></td>
      <td><p><a class="xref" href="C1.Win.FlexGrid.CellRange.html">CellRange</a> that specifies the cells that will be assigned a new value.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></td>
      <td><span class="parametername">value</span></td>
      <td><p>Value that will be assigned to all cells in the range.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></td>
      <td><span class="parametername">coerce</span></td>
      <td><p>Whether the value should be converted to the column's data type.</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.boolean">bool</a></td>
      <td><p>True if the value was assigned to all cells in the destination range.</p>
</td>
    </tr>
  </tbody>
</table>


<a id="C1_Win_FlexGrid_C1FlexGridBase_SetData_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.SetData*"></a>
<h4 id="C1_Win_FlexGrid_C1FlexGridBase_SetData_System_Int32_System_Int32_System_Object_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.SetData(System.Int32,System.Int32,System.Object)">SetData(int, int, object)</h4>
<div class="markdown level1 summary"><p>Assigns a value to a grid cell, coercing the value into the cell's specified DataType.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public virtual bool SetData(int row, int col, object value)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Overridable Function SetData(row As Integer, col As Integer, value As Object) As Boolean</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.object">object</a></td>
      <td><span class="parametername">value</span></td>
      <td><p>Value to assign to the cell.</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.boolean">bool</a></td>
      <td><p>True if the value was assigned to the cell, false if the value could not be
assigned (usually because it could not be converted to the appropriate type).</p>
</td>
    </tr>
  </tbody>
</table>


<a id="C1_Win_FlexGrid_C1FlexGridBase_SetData_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.SetData*"></a>
<h4 id="C1_Win_FlexGrid_C1FlexGridBase_SetData_C1_Win_FlexGrid_CellRange_System_Object_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.SetData(C1.Win.FlexGrid.CellRange,System.Object)">SetData(CellRange, object)</h4>
<div class="markdown level1 summary"><p>Assigns a value to a range of cells, coercing the value into each cell's specified DataType.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public virtual bool SetData(CellRange rg, object value)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Overridable Function SetData(rg As CellRange, value As Object) As Boolean</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.Win.FlexGrid.CellRange.html">CellRange</a></td>
      <td><span class="parametername">rg</span></td>
      <td><p><a class="xref" href="C1.Win.FlexGrid.CellRange.html">CellRange</a> that specifies the cells that will be assigned a new value.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></td>
      <td><span class="parametername">value</span></td>
      <td><p>Value that will be assigned to all cells in the range.</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.boolean">bool</a></td>
      <td><p>True if the value was assigned to all cells in the destination range, false if
the value could not be assigned to all cells in the range (usually because it could not be
converted to the appropriate type).</p>
</td>
    </tr>
  </tbody>
</table>


<a id="C1_Win_FlexGrid_C1FlexGridBase_SetData_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.SetData*"></a>
<h4 id="C1_Win_FlexGrid_C1FlexGridBase_SetData_System_Int32_System_String_System_Object_System_Boolean_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.SetData(System.Int32,System.String,System.Object,System.Boolean)">SetData(int, string, object, bool)</h4>
<div class="markdown level1 summary"><p>Assigns a value to a grid 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 bool SetData(int row, string colName, object value, bool coerce)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Overridable Function SetData(row As Integer, colName As String, value As Object, coerce As Boolean) As Boolean</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.string">string</a></td>
      <td><span class="parametername">colName</span></td>
      <td><p>Column name.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></td>
      <td><span class="parametername">value</span></td>
      <td><p>Value to assign to the cell.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></td>
      <td><span class="parametername">coerce</span></td>
      <td><p>Whether the value should be converted to the column's data type.</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.boolean">bool</a></td>
      <td><p>True if the value was assigned to the cell, False otherwise.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Win_FlexGrid_C1FlexGridBase_SetData_System_Int32_System_String_System_Object_System_Boolean__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>If <code class="paramref">coerce</code> is set to true and the value can't be converted into 
the proper data type, the grid will fire the <a class="xref" href="C1.Win.FlexGrid.C1FlexGridBase.GridError.html">GridError</a> event and the 
cell will retain its original value.</p>
<p>Using <a class="xref" href="C1.Win.FlexGrid.C1FlexGridBase.SetData.html#C1_Win_FlexGrid_C1FlexGridBase_SetData_System_Int32_System_Int32_System_Object_System_Boolean_">SetData(int, int, object, bool)</a> with <code class="paramref">coerce</code> set to true is equivalent 
to setting the grid's indexer. For example, the following lines of code are equivalent:</p>
<pre><code class="lang-csharp">flex.SetData(1, "ColName", "Hello", true);
flex[1, "ColName"] = "Hello"; // same thing</code></pre>
</div>


<a id="C1_Win_FlexGrid_C1FlexGridBase_SetData_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.SetData*"></a>
<h4 id="C1_Win_FlexGrid_C1FlexGridBase_SetData_System_Int32_System_String_System_Object_" data-uid="C1.Win.FlexGrid.C1FlexGridBase.SetData(System.Int32,System.String,System.Object)">SetData(int, string, object)</h4>
<div class="markdown level1 summary"><p>Assigns a value to a grid cell, coercing the value into the cell's specified data type.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public virtual bool SetData(int row, string colName, object value)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Overridable Function SetData(row As Integer, colName As String, value As Object) As Boolean</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.string">string</a></td>
      <td><span class="parametername">colName</span></td>
      <td><p>Column name.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.object">object</a></td>
      <td><span class="parametername">value</span></td>
      <td><p>Value to assign to the cell.</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.boolean">bool</a></td>
      <td><p>True if the value was assigned to the cell, False otherwise.</p>
</td>
    </tr>
  </tbody>
</table>
</div>
