[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
    Supported Formats
   [Expand]Getting Started
   [Expand]RichEditControl Document
   [Expand]Fields
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Printing
    AutoCorrect
    Mail Merge
    Restrictions and Protection
    Syntax Highlighting
    Traversing the Document
   [Expand]Visual Elements
    Services
    Events
    Commands
    HTML Tag Support
   [Collapse]Examples
    [Expand]UI Customization
    [Expand]Files
    [Expand]Text
    [Expand]Formatting
    [Expand]Styles
    [Expand]Lists
    [Expand]Pictures
    [Expand]Text Boxes
    [Expand]Tables
    [Expand]Document Elements
    [Expand]Layout
    [Collapse]Automation
      How to: Insert a Field to a Document
      How to: Create a Table of Contents
      How to: Create TOC for Special Cases
      How to: Create a Table of Contents in Code
      How to: Handle the HyperlinkClick Event to Invoke the Custom Form
    [Expand]Mail Merge
     Spell Check
    [Expand]Export
    [Expand]Printing
    [Expand]Protection
    [Expand]Commands
    [Expand]Miscellaneous
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Create a Table of Contents in Code

This topic demonstrates how to create a table of contents of different types using the RichEdit API.
To create a TOC, perform the following steps.

  1. Mark the Entries
    To include the desired headings into the table of contents, mark the corresponding paragraphs as table entries.

  2. Build the Table of Contents
    The table of contents in RichEditControl is represented by the TOC field.

Expanded Mark the Entries

RichEditControl provides the following approaches to mark a document text (heading) to include it into the table of contents.

  • Outline Levels
  • Set the outline level to paragraphs that should be included into the table of contents. To do that, use the Paragraph.OutlineLevel property as shown in the code sample below. Note that the maximum outline level is 9.

    Show Me

    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T488553.

  • Heading Styles
    1. Create a new heading style or retrieve an existing one from the ParagraphStyleCollection collection (can be accessed through the Document.ParagraphStyles property) and apply it to the target paragraphs. For that, use the ParagraphProperties.Style property as shown in the following code snippet.

      Show Me

      A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T488553.

  • TC Fields
  • Insert a TC field at the beginning of the target paragraph. Type the caption in the field switch, and it will be reflected in the table of contents instead of the original title.

    Show Me

    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T488553.

  • SEQ Fields
  • Use these fields to mark the captions of document figures/tables/equations and include them into the corresponding table. Insert a caption into the target figure and mark it with the SEQ field as shown n the code snippet below.

    Show Me

    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T488553.

    Expanded 2. Build the Table of Contents

    Insert the TOC field with the corresponding switch into the desired position within the document using the following API.

    Member Description
    SubDocument.BeginUpdate Initialize the document modification.
    SubDocument.Paragraphs Provides access to the target paragraph.
    FieldCollection.Create Inserts a field into the given position within the document.
    Depending on the selected approach, use one of the following field switches.
  • \u - for outline levels
  • none - for heading styles
  • \f identifier - for TC fields
  • \c identifier - for SEQ fields
  • Field.Update Updates the given field.
    SubDocument.EndUpdate Finalizes the document update.
    Tip

    To insert all TOC entries as hyperlinks, use the \h switch. You can use other TOC field switches to modify any kind of TOC to fit your needs.

    The code sample below inserts a TOC field into the given document position.

    Show Me

    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T488553.

    Expanded See Also

    Is this topic helpful?​​​​​​​