Example 44 : floating footer usage

vcl grid floating footer

With the floating footer (for which the settings are organised in the property grid.FloatingFooter) an always visible fixed footer can be displayed in the grid. The floating footer can currently be organised in 3 different ways set by the FooterStyle property :


With the fsFixedLastRow style, the last row is always displayed in the fixed floating footer instead of in regular grid cells. With the fsFixedLastRow style, all columns are displayed in the fixed footer in the same way these would be displayed normally in the last row. This means that all settings that affect display of row with index RowCount - 1 (= last row) apply to the display of the fixed floating footer.

In fsColumnPreview mode, the fixed floating footer displays the column set by grid.FloatingFooter.Column: Integer for the current focused row. This can be used as a convenient way to display cell contents that would not fit in a small column, in the full grid width of the fixed floating footer for the selected row.

Finally, the fsCustomPreview mode enables combined column previewing through the CustomTemplate. With the custom template, different column contents can be shown by a referencing HTML tag. Suppose column 1 contains the name of a person, column 2 the prename and column 3 the address. This can be combined in a convenient preview of full name and address through a CustomTemplate like :

'Person : <B><#1> <#2></B> Address : <i><#3>';

In this sample application, the fsFixedLastRow style is choosen and the last row is used to display the column sums. The following method puts the column sums into the last row:

procedure TForm1.UpdateSums;
  i: Integer;
  for i := 1 to AdvStringGrid1.ColCount - 1 do
    AdvStringGrid1.Floats[i,AdvStringGrid1.RowCount - 1] :=
      AdvStringGrid1.ColumnSum(i,1,AdvStringGrid1.RowCount - 2);

To synchronise updating the floating footer whenever a cell value changes through editing, the UpdateSums method is called from the OnCellValidate event which is triggered whenever editing changes a cell.

procedure TForm1.AdvStringGrid1CellValidate(Sender: TObject; Col,
Row: Integer; var Value: String; var Valid: Boolean);

Delphi project & source files for downloading included in the main demos distribution for Delphi.