FlexGrid for WinForms | ComponentOne
C1.Win.FlexGrid Namespace / ColumnCollection Class / IndexOf Method / IndexOf(String,Boolean,Int32) Method
Column name to look for (case-insensitive).
Whether to throw and exception if the column cannot be found.
The search starting index.
Example

In This Topic
    IndexOf(String,Boolean,Int32) Method
    In This Topic
    Gets the index of the Column with the specified name, optionally throwing an exception if the column is not found. The search starts at a specified index.
    Syntax
    'Declaration
     
    
    Public Overloads Function IndexOf( _
       ByVal columnName As String, _
       ByVal throwIfNotFound As Boolean, _
       ByVal startIndex As Integer _
    ) As Integer

    Parameters

    columnName
    Column name to look for (case-insensitive).
    throwIfNotFound
    Whether to throw and exception if the column cannot be found.
    startIndex
    The search starting index.

    Return Value

    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.
    Remarks
    If the throwIfNotFound parameter is set to true and a column named columnName cannot be found, the control throws an System.ArgumentOutOfRangeException. This makes it easier to write compact code that relies on column names.
    Example
    The example below uses the IndexOf method to convert column names into indices. Note that if the column names are invalid, the exception will be thrown by the IndexOf method (column not found) rather than in the following method, where it would not be as clear (invalid index).
    int columnIndex = _flex.Cols.IndexOf("total");
    _flex.AutoSizeCol(columnIndex);
    See Also