Example 42 : merged cell printing

vcl grid printing

The project demonstrates various interesting new capabilities for using TAdvStringGrid 2.0. First of all, it shows the use of the method grid.MergeColumnCells(ColIndex: Integer; MainMergeColumn: Boolean). Where grid.MergeCells merges a selected range of cells in the grid, MergeColumnCells will automatically merge identical succesive cells in the selected column. In the example, the first column contains the car brand names in alphabetical order. Calling grid.MergeColumnCells will automatically merge all cells with identical car brand names. The second parameter of the MergeColumnCells method, indicates whether this is the main merged column or a secondary merged column. When the second parameter is false, rows of the selected column will only be merged when the cells are part of another main merged block of rows.

An example makes this more clear:

Suppose the grid is sorted alphabetically on car brand and a secondary sort on the number of cylinders. First, the MergeColumnCells is applied as a main merged column for the column that contains the car brand name. After this, the column with number of cylinders need to be merged. It is very likely that succesive cells for 4 cylinders belong to different car brand names. With a MergeColumnCells(cylindercolumn, True) call, these cells with identical cylinders would be merged irrespective of the car brand these belong to. With the call MergeColumnCells(cylindercolumn, False), the merged car brand name column is taken into account and only rows within a merged row block of the car brand will be merged in the cylinder column.

Further this project demonstrates the use of bitmap resources and automatic picture creation. A resource file holds several bitmaps representing the car brand logos. After applying the merge, the correct bitmap is created for the base cell only of the merged car brand cell block with :

AdvStringGrid.CreateBitmap(ACol,ARow,True,haCenter,vaAboveText).LoadFromResourceName(hinstance, CarBrandName);

It takes no further effort to print this grid. Simply calling grid.Print will print the grid as displayed on screen.

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