Skip to content

Column Widths and Horizontal Scrolling

Individual column widths are controlled by setting each column object's piWidth property. In the Studio's Designer, this can be done by editing the piWidth property in the Properties Panel, or by dragging the column dividers in the grid header.

The value of each column's piWidth is interpreted as either the width of the column in pixels or as a ratio of the column's width relative to other columns in the grid. Which way the width is calculated is controlled by the grid's pbAutoColumnSizing property.

When pbAutoColumnSizing is True (the default), then piWidth determines each column's size relative to the other columns, and these sizes are automatically scaled to fit inside the grid's client area. If the grid is widened or made narrower, then the column widths are scaled appropriately. When pbAutoColumnSizing is True, the visible columns always fit perfectly inside the grid; there is no gap and no horizontal scrollbar.

When pbAutoColumnSizing is False, then the columns' piWidth values are interpreted as the width, in pixels, of each column. If the columns are not wide enough to fill the entire width of the grid, then there will be a gap between the last column and the right edge of the grid. If the columns are wider than the grid, then a horizontal scrollbar will appear so that the rightmost columns can be scrolled into view.

When your program is running, the user can adjust each column width by dragging the column dividers in the grid header. Setting a column's pbResizable property to False prevents that column from being resized by the user. The grid's pbAllowColumnResize property can be set to False to prevent any column from being resized by the user.

When the grid object is using Auto Column Sizing and a column's pbResizable property is False, then that column is not automatically scaled to fit the grid width. Instead, the piWidth value becomes the pixel width for that column. The widths of the remaining columns are then scaled to fit inside the space remaining after the non-resizable column's width is subtracted from the width of the grid.

Freeze Columns

The piFreezeColumnsCount property can be used to prevent horizontal scrolling of one or more left-most columns. For example, if this property is set to 2, then when you drag the horizontal scrollbar, all columns will scroll sideways except for the left two columns. If pbAutoColumnSizing is set to True, you will never see a horizontal scrollbar, and thus piFreezeColumnsCount is ignored.

To specify that the freeze columns begin at a particular column, send FreezeColumn passing the desired column object handle. The passed column and all columns to its left will be frozen for horizontal scrolling.

Other grid properties, piFreezeColsDividerColor and peFreezeColsDividerStyle, control the appearance of a vertical divider that is painted between the freeze columns and the columns that are horizontally scrolled.

See Also