The table of contents in RichEditControl is represented by the TOC field.

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.

richEditControl1.LoadDocument("Documents//Table of Contents.docx")
'Set the outline level to every chapter title in the document
For i As Integer = 0 To richEditControl1.Document.Paragraphs.Count - 1
Dim var As String = richEditControl1.Document.GetText(richEditControl1.Document.Paragraphs(i).Range)
If var.Contains("CHAPTER ") Then
richEditControl1.Document.Paragraphs(i).OutlineLevel = 2
End If
Next i

richEditControl1.LoadDocument("Documents//Table of Contents.docx")
'Apply the "heading 1" style to every chapter title in the document
For i As Integer = 0 To richEditControl1.Document.Paragraphs.Count - 1
Dim var As String = richEditControl1.Document.GetText(richEditControl1.Document.Paragraphs(i).Range)
If var.Contains("CHAPTER ") Then
richEditControl1.Document.Paragraphs(i).Style = richEditControl1.Document.ParagraphStyles("heading 1")
End If
Next i

richEditControl1.LoadDocument("Documents//Table of Contents.docx")
Dim j As Integer = 1
'Mark every chapter title in the document by the TC field
For i As Integer = 0 To richEditControl1.Document.Paragraphs.Count - 1
Dim var As String = richEditControl1.Document.GetText(richEditControl1.Document.Paragraphs(i).Range)
If var.Contains("CHAPTER ") Then
Dim field As Field = richEditControl1.Document.Fields.Create(richEditControl1.Document.Paragraphs(i).Range.Start, String.Format("TC {0} \f bvz ", j))
richEditControl1.Document.Fields.Update()
j += 1
End If
Next i

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.

richEditControl1.LoadDocument("Documents//Table of Contents.docx")
document.BeginUpdate()
For i As Integer = 0 To document.Images.Count - 1
Dim shape As DocumentImage = document.Images(i)
Dim paragraph As Paragraph = document.Paragraphs.Insert(shape.Range.End)
'Insert caption to every image in the document
Dim range As DocumentRange = document.InsertText(paragraph.Range.Start, "Image ")
'Mark the captions with the SEQ fields
Dim field As Field = document.Fields.Create(range.End, "SEQ Image \*ARABIC")
Next i
document.Fields.Update()
document.EndUpdate()