PRODUCTS

FEATURED PRODUCT

Office 2007 ribbon bar or Office 2003 toolbar & menus for your Windows applications

License only 75 EUR See More

SEARCH

LOGIN

Customer login to access products, support information & special benefits.

NEWS ALERTS

Add your e-mail address here to receive the monthly TMS Software alerts.

 

LINKS

EXAMPLE 66

TAdvStringGrid

example 66 : Using OnPrintNewPage to start a new page for new data in a column

TAdvStringGrid

Normally during the printing of a grid, it is the grid that decides when to start a new page, ie. when a row can no longer fit on the page being printed a new page is started. In some cases, it is desirable to customize this behaviour. In the sample below, it could be a feature request that one contains information from only one car brand. Therefore, it is required to force a new page during the printing of the grid. The OnPrintNewPage was specifically added for this purpose. This event is triggered before the printing of each row in the grid. It returns the actual row number that will be printed and has a boolean parameter NewPage through which a page break can be forced.

In this simple OnPrintNewPage event handler, the first normal column value of the row that is to be printed is compared with the previous value and when different, a new page is caused by setting the parameter NewPage = true:

procedure TForm1.AdvStringGrid1PrintNewPage(Sender: TObject; ARow: Integer;
var NewPage: Boolean);
begin
  NewPage := false;
  if (ARow > 1) then
    NewPage := (AdvStringGrid1.Cells[0, ARow - 1] <> 
AdvStringGrid1.Cells[0, ARow]);
end;

This shows how with a very little code, the page breaks during grid printing can be programmatically controlled.

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

The project and source files have been written with Delphi 6,7. To use these files in other versions of Delphi, ignore any remarks when opening the form files and save the files. After this, compilation can be done. The error messages are due to properties included in the Delphi 6 form file, but not available in lower versions of Delphi.  

Copyright © 1995 - 2008 TMS Software