# C1.Win.FlexGrid.ColumnCollection.IndexOf

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_Win_FlexGrid_ColumnCollection_IndexOf_" data-uid="C1.Win.FlexGrid.ColumnCollection.IndexOf*">IndexOf Method
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_Win_FlexGrid_ColumnCollection_IndexOf_" data-uid="C1.Win.FlexGrid.ColumnCollection.IndexOf*"></a>
<h4 id="C1_Win_FlexGrid_ColumnCollection_IndexOf_System_String_" data-uid="C1.Win.FlexGrid.ColumnCollection.IndexOf(System.String)">IndexOf(string)</h4>
<div class="markdown level1 summary"><p>Gets the index of the <a class="xref" href="C1.Win.FlexGrid.Column.html">Column</a> with the specified name.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public int IndexOf(string columnName)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Function IndexOf(columnName As String) 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.string">string</a></td>
      <td><span class="parametername">columnName</span></td>
      <td><p>Column name to look for (case-insensitive).</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.int32">int</a></td>
      <td><p>Index of the column that has the given name in this collection, or -1 if the collection
does not contain a column with the given name.</p>
</td>
    </tr>
  </tbody>
</table>


<a id="C1_Win_FlexGrid_ColumnCollection_IndexOf_" data-uid="C1.Win.FlexGrid.ColumnCollection.IndexOf*"></a>
<h4 id="C1_Win_FlexGrid_ColumnCollection_IndexOf_System_String_System_Int32_" data-uid="C1.Win.FlexGrid.ColumnCollection.IndexOf(System.String,System.Int32)">IndexOf(string, int)</h4>
<div class="markdown level1 summary"><p>Gets the index of the <a class="xref" href="C1.Win.FlexGrid.Column.html">Column</a> with the specified name. The search starts at a specified index.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public int IndexOf(string columnName, int startIndex)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Function IndexOf(columnName As String, startIndex As Integer) 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.string">string</a></td>
      <td><span class="parametername">columnName</span></td>
      <td><p>Column name to look for (case-insensitive).</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">startIndex</span></td>
      <td><p>The search starting 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="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><p>Index of the column that has the given name in this collection, or -1 if the collection
does not contain a column with the given name.</p>
</td>
    </tr>
  </tbody>
</table>


<a id="C1_Win_FlexGrid_ColumnCollection_IndexOf_" data-uid="C1.Win.FlexGrid.ColumnCollection.IndexOf*"></a>
<h4 id="C1_Win_FlexGrid_ColumnCollection_IndexOf_System_String_System_Boolean_" data-uid="C1.Win.FlexGrid.ColumnCollection.IndexOf(System.String,System.Boolean)">IndexOf(string, bool)</h4>
<div class="markdown level1 summary"><p>Gets the index of the <a class="xref" href="C1.Win.FlexGrid.Column.html">Column</a> with the specified name, optionally
throwing an exception if the column is not found.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public int IndexOf(string columnName, bool throwIfNotFound)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Function IndexOf(columnName As String, throwIfNotFound As Boolean) 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.string">string</a></td>
      <td><span class="parametername">columnName</span></td>
      <td><p>Column name to look for (case-insensitive).</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></td>
      <td><span class="parametername">throwIfNotFound</span></td>
      <td><p>Whether to throw and exception if the column cannot be found.</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.int32">int</a></td>
      <td><p>Index of the column that has the given name in this collection, or -1 if the collection
does not contain a column with the given name.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Win_FlexGrid_ColumnCollection_IndexOf_System_String_System_Boolean__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>If the <code class="paramref">throwIfNotFound</code> parameter is set to true and
a column named <code class="paramref">columnName</code> cannot be found, the control throws
an <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception">ArgumentOutOfRangeException</a>. This makes it easier to write
compact code that relies on column names.</p>
</div>
<h5 id="C1_Win_FlexGrid_ColumnCollection_IndexOf_System_String_System_Boolean__examples">Examples</h5>
<p>The example below uses the <b>IndexOf</b> method to convert column names into
indices. Note that if the column names are invalid, the exception will be thrown
by the <b>IndexOf</b> method (column not found) rather than in the following
method, where it would not be as clear (invalid index).</p>
<pre><code class="lang-csharp">int columnIndex = _flex.Cols.IndexOf("total");
_flex.AutoSizeCol(columnIndex);</code></pre>



<a id="C1_Win_FlexGrid_ColumnCollection_IndexOf_" data-uid="C1.Win.FlexGrid.ColumnCollection.IndexOf*"></a>
<h4 id="C1_Win_FlexGrid_ColumnCollection_IndexOf_System_String_System_Boolean_System_Int32_" data-uid="C1.Win.FlexGrid.ColumnCollection.IndexOf(System.String,System.Boolean,System.Int32)">IndexOf(string, bool, int)</h4>
<div class="markdown level1 summary"><p>Gets the index of the <a class="xref" href="C1.Win.FlexGrid.Column.html">Column</a> with the specified name, optionally
throwing an exception if the column is not found. The search starts at a specified index.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public int IndexOf(string columnName, bool throwIfNotFound, int startIndex)</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Function IndexOf(columnName As String, throwIfNotFound As Boolean, startIndex As Integer) 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.string">string</a></td>
      <td><span class="parametername">columnName</span></td>
      <td><p>Column name to look for (case-insensitive).</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.boolean">bool</a></td>
      <td><span class="parametername">throwIfNotFound</span></td>
      <td><p>Whether to throw and exception if the column cannot be found.</p>
</td>
    </tr>
    <tr>
      <td><a class="xref" href="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><span class="parametername">startIndex</span></td>
      <td><p>The search starting 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="https://learn.microsoft.com/dotnet/api/system.int32">int</a></td>
      <td><p>Index of the column that has the given name in this collection, or -1 if the collection
does not contain a column with the given name.</p>
</td>
    </tr>
  </tbody>
</table>
<h5 id="C1_Win_FlexGrid_ColumnCollection_IndexOf_System_String_System_Boolean_System_Int32__remarks">Remarks</h5>
<div class="markdown level1 remarks"><p>If the <code class="paramref">throwIfNotFound</code> parameter is set to true and
a column named <code class="paramref">columnName</code> cannot be found, the control throws
an <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.argumentoutofrangeexception">ArgumentOutOfRangeException</a>. This makes it easier to write
compact code that relies on column names.</p>
</div>
<h5 id="C1_Win_FlexGrid_ColumnCollection_IndexOf_System_String_System_Boolean_System_Int32__examples">Examples</h5>
<p>The example below uses the <b>IndexOf</b> method to convert column names into
indices. Note that if the column names are invalid, the exception will be thrown
by the <b>IndexOf</b> method (column not found) rather than in the following
method, where it would not be as clear (invalid index).</p>
<pre><code class="lang-csharp">int columnIndex = _flex.Cols.IndexOf("total");
_flex.AutoSizeCol(columnIndex);</code></pre>

</div>
