ThgHeading Properties

ThgColumn Properties

Most of THyperGrid's special formatting features are stored in its Columns collection, so an explanation of how they work is offered here.

Grid Columns and Column Objects

For starters, we must make a clear distinction between grid columns and column objects, because, as you will see, they don't always correspond. In the simplest case, when you drop a grid on a form, it has five columns and so, THyperGrid creates five column objects each corresponding to a column in the grid. So, by indexing into the columns property, you can obtain the column object for each grid column.

THyperGrid also allows you to hide columns, or make them invisible, which is not supported by the standard TStringGrid. To accomplish this, THyperGrid has to remove the column from the grid and store its contents until you make it visible again. Lets say that we have a grid with 3 columns. It would have three column objects in and three grid columns. Now, lets say you hide column 1 ( the second column because they are zero based ): THyperGrid removes the grid column 1 and stores its contents in column object 1. Now, the grid has two grid columns 0 and 1, but three column objects, where column object 0 corresponds to grid column 0, column object 1 does not have a grid column and column object 2 corresponds to grid column 1.

The property VisibleColumns lets you find a column object for a grid column. So in this case:

VisibleColumns[ 0 ] = Columns[ 0 ]
VisibleColumns[ 1 ] = Columns[ 2 ]

Going the other way, the method GridColumnForColumnObject lets you retrieve the grid column for a given column object, so, in the same case:

GridColumnForColumnObject( Columns[ 0 ] ) = 0
GridColumnForColumnObject( Columns[ 1 ] ) = -1     because column object 1 does not have a grid column
GridColumnForColumnObject( Columns[ 2 ] ) = 1

This takes a little getting used to, but makes sense.

Column Objects and Heading Objects

Each grid column is divided into possibly three sections: the scrolling cells, the title - which is the fixed cell above the scrolling cells and the heading, which is a new concept introduced by THyperGrid. A heading is a fixed column which spans one or more other fixed columns, so that it creates a super-column, such as this:

headings.gif (3172 bytes)

Headings are created ( by THyperGrid ) by splitting the first fixed row into two sections, using the top part to span the columns. In this case, there are 4 grid columns, 4 column objects and 1 heading object. The headings are contained in the Headings property, and the columns in the Columns property. Each column can have a Heading Index which allows you to specify which heading the column will reside under. This is all apparent when you use the Columns or Headings property editor.

To complicate matters even further, I have used two types to represent Column and Heading objects. You can look at it this way:

The ThgHeading class is used to store properties for any fixed cell,
The ThgColumn class is derived from ThgHeading and adds all the properties necessary for the scrolling cells.

So, the Headings property is a list of pure ThgHeading objects which hold the properties for each heading.
The Columns property is a list of ThgColumn objects, which hold all the properties for the title in the ThgHeading portion and the properties for the scrolling cells in the rest.