Skip to main content

Add a Table of Contents (TOC)

  • 3 minutes to read

This tutorial adds a table of contents (TOC) to a report. You start with a master-detail report, specify bookmarks for report controls, add an XRTableOfContents control to the form, specify its title, and apply custom formatting to TOC entries at different nesting levels.

Overview

A table of contents (TOC) displays page numbers for bookmarked report elements at different nesting levels.

The following image displays a table of contents in a report designer and in a published document:

Table-of-Contents-Concepts00

A table of contents contains the following elements:

Title
The XRTableOfContentsTitle class defines the title text and format. Use the XRTableOfContents.LevelTitle property to access the TOC title.
Levels

You can specify one or more levels. The XRTableOfContentsLevel class defines format settings for nodes in a document map tree.

To access the collection of levels, use the XRTableOfContents.Levels property.

The table of contents initially includes one default level. It specifies common settings for elements of the document map that do not yet have a specific level assigned to them.

If you export a report to a tagged PDF (accessibility-compliant format like PDF/UA a table of content is automatically converted into TOCI entries. These entries help screen readers and accessibility tools interpret the PDF document’s structure.

You can see a TOC example in the following demo:

Run Demo: Reporting for WinForms

Create a Table of Contents

  1. Create a master-detail report with the following layout:

    Howto-Table-of-Contents-Reports0

  2. Specify bookmarks for report elements that need to be included in the table of contents.
  3. Open the Toolbox panel (by pressing CTRL+ALT+X), select the XRTableOfContents control in the DX.25.1: Report Controls category and drop it onto the report surface. The control appears on the Report Header band. This band is created automatically if the report does not have one.

    Howto-Table-of-Contents-Reports1

  4. Customize the table of contents title using the XRTableOfContents.LevelTitle property.

    Howto-Table-of-Contents-Reports2

  5. When report bookmarks are organized into a hierarchy (by setting the nested elements’ XRControl.BookmarkParent property), the corresponding levels are displayed in the table of contents. You can specify each level’s text formatting options individually.

    Access the level collection by clicking the control’s smart tag and using the XRTableOfContents.Levels property.

    Howto-Table-of-Contents-Reports3

    In the collection editor, click Add to add a new level and adjust its settings.

    Howto-Table-of-Contents-Reports4

    You can limit the maximum number of levels the table of contents displays using the XRTableOfContents.MaxNestingLevel property.

  6. The XRTableOfContents.LevelDefault property allows you to specify common level formatting settings. These settings apply to levels that you did not customize explicitly.

    Howto-Table-of-Contents-Reports5

The following image demonstrates the result in Print Preview:

Howto-Table-of-Contents-Reports6