Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [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]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
   [Expand]Getting Started
   [Expand]RichEditControl Document
   [Expand]Fields
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Printing
    Spell Checking
    AutoCorrect
    Mail Merge
    Restrictions and Protection
    Syntax Highlighting
    Traversing the Document
   [Expand]Visual Elements
    Services
    Events
    Commands
   [Expand]Member Tables
    Keyboard Shortcuts
    HTML Tag Interpretation
   [Collapse]Examples
    [Expand]Files
    [Expand]Text
    [Expand]Formatting
    [Expand]Styles
    [Expand]Lists
    [Expand]Pictures
    [Expand]Text Boxes
    [Expand]Tables
    [Expand]Layout
    [Collapse]Automation
      How to: Create a Table of Contents
      How to: Create a Table of Contents in Code
      How to: Add and Modify Fields
      How to: Handle the HyperlinkClick Event to Invoke the Custom Form
    [Expand]Search and Replace
    [Expand]Mail Merge
    [Expand]Spell Check
    [Expand]Export-Import
    [Expand]Printing
    [Expand]Protection
    [Expand]User Interface Customization
    [Expand]Miscellaneous
    [Expand]Commands
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap 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]Document Server
[Expand]Reporting
[Expand]Report 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

    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

How would you rate this topic?​​​​​​​