[Expand]General Information
[Collapse]WinForms Controls
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Map Control
  [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
    Spell Checking
    AutoCorrect Feature
    Mail Merge
    Restrictions and Protection
   [Expand]Visual Elements
    Keyboard Shortcuts
    HTML Tag Support
    [Expand]Text Boxes
    [Expand]Document Elements
      How to: Create a Table of Contents
      How to: Create a Table of Contents in Code
      How to: Handle the HyperlinkClick Event to Invoke the Custom Form
      How to: Retrieve the List of Document Fonts using the Visitor-Iterator Pattern
      How to: Highlight Document Syntax
      How to: Insert Dynamic Content
    [Expand]Search and Replace
    [Expand]Spell Check
    [Expand]Import and Export
    [Expand]UI Customization
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[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

    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?​​​​​​​