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

# TCustomGrid.Columns

Definitions for the columns displayed the grid.

## Declaration

Source position: grids.pas line 1236

`protected property TCustomGrid.Columns : TGridColumns read GetColumns write SetColumns stored IsColumnsStored;`

## Description

Columns is a TGridColumns which contains column definitions for the grid control. Columns stores the TGridColumn instances which define the attributes for each of the columns such as its Font, Color, Alignment, Layout, Editor style, auto-sizing priority, et. al. Properties and methods in Columns can be used at run-time to access and maintain the column definitions for the grid.

See TGridColumn for more information about the items stored in the collection.

Columns contains definitions for the non-fixed columns on the grid control. For a grid with 5 columns, and FixedCols set to 1, there would need to be 4 definitions added to the Columns collection. ColCount is automatically maintained when items are added to or deleted from Columns. When Columns is enabled, a value cannot be directly assigned to ColCount; it is calculated as:.

    ColCount := FixedCols + Columns.Count

Values in the collection can be modified at run-time to add, delete, or modify column definitions. For example:

    var
        c: TGridColumn;
      begin
        // add a custom column
        c := Grid.Columns.Add;
        // modify the new column
        c.title.caption := 'Price';       // Set columns caption
        c.align := taRightJustify;        // Align column content to the right
        c.color := clMoneyGreen;          // Change default color to clMoneyGreen
        c.Index := 0;                     // Make it the first column
        // access an existing column
        grid.columns[0].Width := 60;      // Change column 0 width to 60 pixels
        // delete an existing column
        grid.columns.delete(0);           // Delete column 0
        ....
      end;

Columns should not be confused with the COLUMNS construct frequently used in SQL programming, which refer to Fields in a database table. The content in fields can be displayed as Columns in a Grid, but they must be seen as separate and distinct. It is irrelevant to refer to the color, font or width of a data field from a database - but these are all very relevant in specifying the appearance of a column in a grid.

## See also

TGridColumns |  | Collection used to store column definitions for a grid control.
TGridColumn |  | Implements a column definition used for tabular data in TCustomGrid.