Printing a table

Top  Previous  Next

A table can be printed in two modes:

 

In the first mode, the table is printed inside the band which it belongs to, and looks just the same as in the designer. In this mode, the table does not split across pages if its width is bigger than the width of the report page. This is the mode of printing by default.

 

The second mode is dynamic. In this mode, the table is built with the help of script. During this, the resulting table can be different from the initial table, just like the prepared report of FastReport differs from the report template. In dynamic mode, the table can split across pages if it does not fit on the report page.

 

In the dynamic mode, the table does not get printed on the band on which it was placed. Instead of this, the table itself generates a set of bands, which contain parts of the resulting table. This mode of work imposes the following limits:

 

never put other objects under the table or near it. Instead of this, use the "Child" band;
never put two "Table "objects on one band.

 

Let us look at the dynamic mode in details.

 

 

This mode is connected with programming and needs higher qualifications from the report developer.

 

Formation of the table is done with the help of script. In order to create a script, select the "Table" object, in the "Properties" window click the "Events" button and double click on ManualBuild event:

 

tableManualBuild1

 

When this is done, an empty event handler is added into the report code:

 

private void Table1_ManualBuild(object sender, EventArgs e)

{

 

}

 

In this mode, the source table is used as a template. In the event code, you can print rows and columns from the source table as many times as it is needed. During this, the resulting table will be formed, which can contain an unlimited number of rows and columns. Such a table can split across pages if it does not fit on the report page.

 

For printing a table, the following methods of the "Table" object are used:

 

Method

Parameters

Description

PrintRow

int index

Prints the row with the specified index. Row numbering starts from 0.

PrintColumn

int index

Prints the column with the specified index. Column numbering starts from 0.

PrintRows

int[] indices

Prints several rows of the table.

PrintRows

-

Prints all rows of the table.

PrintColumns

int[] indices

Prints several columns of the table.

PrintColumns

-

Prints all columns of the table.

PageBreak

-

Inserts a page break before printing the next column or row.

 

Printing a table can be done by using one of the following methods:

 

The first method - printing from top to bottom, then from left to right. This method fits better a table with a variable amount of rows. You must call the methods in the following order:

 

PrintRow(row index);
one or more calls of the PrintColumn(column index) or PrintColumns(columns indices) methods for printing the indicated columns;
or one call of the PrintColumns() method for printing all columns;
repeat this sequence in order to print all the needed rows of the table.

 

Every row of the table must contain the same number of columns. Keep it in mind, when using the PrintColumn(int index) and PrintColumns(int [] indices) methods.

 

The second method - printing from left to right, then from top to bottom. This method is better for printing a table with a variable number of columns. You must call the methods in the following sequence:

 

PrintColumn(column index);
one or several calls of the PrintRow(row number) or PrintRows(rows indices) for printing the indicated rows;
or one call of the PrintRows() method for printing all rows;
repeat this sequence in order to print all the needed columns of the table.

 

Every column of the table must contain the same number of rows. Keep it in mind, when using the PrintRow(int index) and PrintRows(int [] indices) methods.

 

Violation of the order of calling the printing methods leads to errors when executing the report. One of the errors - attempting to print the table with the help of the following code:

 

Table1.PrintRows();

Table1.PrintColumns();

 

This sequence of methods is not correct. You must start printing the table with either the PrintRow or PrintColumn method.