[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] | Reference for unit 'Grids' (#lcl)

# TCustomGrid.GridColumnFromColumnIndex

Gets the ordinal position in Columns for the visible column specified in ColumnIndex.

## Declaration

Source position: grids.pas line 1125

`protected function TCustomGrid.GridColumnFromColumnIndex(`
`ColumnIndex: Integer`
`):Integer;`

## Arguments

`ColumnIndex` |  | Ordinal position for the visible column to locate in the Columns collection.

## Function result

Ordinal position in Columns for the visible column in ColumnIndex.

## Description

GridColumnFromColumnIndex is an Integer function used to get the position in Columns for the visible column represented by ColumnIndex. It is necessary because a grid can include 0 or more fixed columns. This is a problem because: A) the fixed columns are both optional and variable, and B) the Columns collection uses ordinal values and never includes a column definition for fixed column.

ColumnIndex refers to the ordinal position for a visible column in the display area for the grid control. The return value is calculated as ColumnIndex + FirstGridColumn. In previous versions of the LCL, the value was derived using values from VisibleIndex and FixedCols.

The return value is -1 if the computed value is larger than ColCount-1.

GridColumnFromColumnIndex is used when a new value is assigned to the Index property in a TGridColumn instance. It is also used in the DialogChar method to locate and perform the OnClick handler for the column header where an accelerator key is found.

## See also

TCustomGrid.FirstGridColumn |  | Gets the position of the first column after any fixed columns in the grid.
TCustomGrid.FixedCols |  | The number of fixed columns in the grid.
TCustomGrid.DialogChar |  | Applies an accelerator key for a column in the grid.
TGridColumn |  | Implements a column definition used for tabular data in TCustomGrid.
TCollectionItem.Index