[]
        
(Showing Draft Content)

C1.Win.FlexGrid.ColumnCollection.IndexOf

IndexOf Method

IndexOf(string)

Gets the index of the Column with the specified name.

Declaration
public int IndexOf(string columnName)
Parameters
Type Name Description
string columnName

Column name to look for (case-insensitive).

Returns
Type Description
int

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.

IndexOf(string, int)

Gets the index of the Column with the specified name. The search starts at a specified index.

Declaration
public int IndexOf(string columnName, int startIndex)
Parameters
Type Name Description
string columnName

Column name to look for (case-insensitive).

int startIndex

The search starting index.

Returns
Type Description
int

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.

IndexOf(string, bool)

Gets the index of the Column with the specified name, optionally throwing an exception if the column is not found.

Declaration
public int IndexOf(string columnName, bool throwIfNotFound)
Parameters
Type Name Description
string columnName

Column name to look for (case-insensitive).

bool throwIfNotFound

Whether to throw and exception if the column cannot be found.

Returns
Type Description
int

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 ArgumentOutOfRangeException. This makes it easier to write compact code that relies on column names.

Examples

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);

IndexOf(string, bool, int)

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.

Declaration
public int IndexOf(string columnName, bool throwIfNotFound, int startIndex)
Parameters
Type Name Description
string columnName

Column name to look for (case-insensitive).

bool throwIfNotFound

Whether to throw and exception if the column cannot be found.

int startIndex

The search starting index.

Returns
Type Description
int

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 ArgumentOutOfRangeException. This makes it easier to write compact code that relies on column names.

Examples

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);