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

# TCustomGrid.AutoFillColumns

Indicates whether columns are automatically resized to fill the visible area in the grid.

## Declaration

Source position: grids.pas line 1224

`protected property TCustomGrid.AutoFillColumns : Boolean read FAutoFillColumns write SetAutoFillColumns default False;`

## Description

AutoFillColumns is a Boolean property which enables or disables automatic sizing for columns on the grid control. The default value for the property is False, and indicates that automatic column sizing is not enabled.

Changing AutoFillColumns to True causes the column sizes to be recalculated (and cached) based on default values, or using properties assigned to the TGridColumn instances when the Columns collection has been Enabled. The resizing algorithm works as follows:

- Fixed columns are not resized.
- When Columns has not been Enabled, or the column position is not found in Columns, a default sizing priority of 1 is used along with the minimum and maximum sizes defined in the DEFMINSIZE and DEFMAXSIZE constants.
- When Columns is Enabled, and a column is defined for a given position, values from the TGridColumn instance are used including: SizePriority, MinSize, and MaxSize.
- A column with a SizePriority of 0 is not resized.
- A column with a non-zero value in SizePriority is adjusted using the average available width with respect to the MinSize and MaxSize for all of the defined columns. When MinSize and MaxSize have the same non-zero value, the column cannot be resized. If all columns have assigned MinSize and MaxSize values, the auto-fill algorithm may not be able to set column widths as intended. At least one of the columns should have MinSize and MaxSize set to 0 for the intended result.
- If Columns is not Enabled (populated), fixed columns are set to the size found in either ColWidths (preferred) or DefaultColWidth (default). Non-fixed columns (starting at FixedCols-1) are uniformly resized to fill the available unused area following the fixed columns.

Please note that TGridColumn instances in Columns are initially created with SizePriority set to 1. For TDbGrid, which automatically populates Columns, this means the user will not be able to resize these columns using the mouse (since they are auto-sized).

Use ColWidths to set the width for a specified column when the Columns collection has not been enabled or populated. Use DefaultColWidth to set the default width used when a width is not available in ColWidths or Columns.

## See also

TCustomGrid.ColWidths |  | Provides indexed access to the Width for a column in the grid.
TCustomGrid.DefaultColWidth |  | Default width used for grid columns.
TCustomGrid.Columns |  | Definitions for the columns displayed the grid.
TCustomGrid.FixedCols |  | The number of fixed columns in the grid.
TCustomGrid.ColCount |  | Number of columns in the grid.
TGridColumns |  | Collection used to store column definitions for a grid control.
TGridColumn.MaxSize |  | The maximum size for the column in pixels.
TGridColumn.MinSize |  | The minimum size for the column in pixels.
TGridColumn.SizePriority |  | The auto-sizing priority for the column.