Example 4. Report with table of contents, navigation and outline

Top  Previous  Next

In this example, we will look at creating a report, which has the following features:

 

on the first page it will print the "Table of Contents" (TOC) which is interactive, i.e. you can click its elements to navigate to the corresponding page;
in the preview window, it will display the outline, which is interactive as well.

 

interactiveExample4

 

The report will use the "Categories" and "Products" tables. In the TOC, we will print the categories list. The rest of report will print the categorized list of products. Report template will be made up of two pages: the first page will be used to print the TOC; the second one is the main part of the report.

 

We will discuss the TOC firstly. Create a new report and add "Categories" and "Products" data sources into it. Connect the "Data" band to the "Categories" table and place the objects in the following way:

 

interactiveExample4_1

 

In order to make the TOC objects interactive, configure its "Hyperlink" property:

 

interactiveExample4_2

 

Indicate the category name as a bookmark. We will define the object's bookmark later.

 

In order to print the page number in the TOC, you need to do the following:

 

enable the "double pass" setting of the report. This can be done in the "Report|Options..." menu. This needs to be done, because the TOC page is printed before other pages. At this moment FastReport does not know where the categories will be printed;
use the "Engine.GetBookmarkPage" function, which returns page number for the specified bookmark. In our case, we use the "[Categories.CategoryName]" expression as a bookmark name, so the function call will be as follows:

 

[Engine.GetBookmarkPage([Categories.CategoryName])]

 

On the second page of the report, we will create a master-detail report as shown in the figure below:

 

interactiveExample4_3

 

Set up the bookmark we navigate to when clicking on an element in the TOC. For this, select the first "Data" band and indicate the following expression in its "Bookmark" property:

 

[Categories.CategoryName]

 

To set up the report outline, do the following:

 

select the first report page. This can be done by switching to the page;
in the "Properties" window, set the following value to the "OutlineExpression" property:

 

"Contents"

 

switch to the second report page;
select the first "Data" band and set its "OutlineExpression" property:

 

[Categories.CategoryName]

 

select the second "Data" and set its "OutlineExpression" property:

 

[Products.ProductName]