[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
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
    Supported Formats
   [Expand]Getting Started
   [Expand]RichEditControl Document
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Track Changes
    Mail Merge
    Restrictions and Protection
   [Expand]Visual Elements
    HTML Tag Support
    [Expand]UI Customization
    [Expand]Text Boxes
      How to: Create a Table of Contents in Code
      How to: Handle the HyperlinkClick Event to Invoke the Custom Form
      How to: Use the Visitor-Iterator Pattern to Retrieve the List of Document Fonts
      How to: Highlight Document Syntax
      How to: Insert Dynamic Content
     Spell Check
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

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.

  • 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.

  • 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.

  • 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.

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.




Initialize the document modification.


Provides access to the target paragraph.


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


Updates the given field.


Finalizes the document update.


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.

Expanded See Also

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