Version

Adding Tables (xamRichTextEditor)

Topic Overview

Purpose

This topic provides information on how to use the xamRichTextEditor ™ to create tables from the developer’s perspective.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

This topic provides an overview of the features supported by the xamRichTextEditor control.

This topic explains the document’s content logical structure you can use to edit the contents in the xamRichTextEditor programmatically.

This topic provides detailed instructions to help you get up and running as quickly as possible with the xamRichTextEditor .

In this topic

This topic contains the following sections:

Introduction to Tables

Table summary

The xamRichTextEditor supports tables, constructed using a table node, holding the row nodes, which in their place are holding cell nodes to display data in a grid format. Use the table cells as containers for other rich content like paragraphs, images and even other tables.

The following tree diagram shows the node’s hierarchy of a table with three columns and two rows using the appropriate types:

  1. TableNode

    1. TableRowNode

      1. TableCellNode

      2. TableCellNode

        1. ParagraphNode

      3. TableCellNode

        1. ParagraphNode

    2. TableRowNode

      1. TableCellNode

        1. ParagraphNode

      2. TableCellNode

        1. ParagraphNode

      3. TableCellNode

        1. ParagraphNode

Note
Note

There must be at least one ParagraphNode or TableNode in the ChildNodes collection of each TableCellNode.

You can create the above structure directly in the ChildNodes collection of the DocumentBodyNode or use the InsertTable method of the RichTextDocument, which conveniently creates the structure for you and returns a reference to the root table node.

Example

The following code snippet demonstrates how to insert a table with three columns and two rows into the beginning of a document (at offset 0), iterate over the structure and put some content in it:

In C#:

string error = null;
TableNode tn = this.xamRichTextEditor1.Document.InsertTable(0, 3, 2, out error);
if (error == null)
{
    int cRow = 1;
    foreach (TableRowNode trn in tn.ChildNodes)
    {
        int cCell = 1;
        foreach (TableCellNode tcn in trn.ChildNodes)
        {
            ParagraphNode pn = tcn.ChildNodes[0] as ParagraphNode;
            pn.SetText(string.Format("Row {0}, Cell {1}", cRow, cCell));
            cCell++;
        }
        cRow++;
    }
}

In Visual Basic:

Dim [error] As String = Nothing
Dim tn As TableNode = Me.xamRichTextEditor1.Document.InsertTable(0, 3, 2, [error])
If [error] Is Nothing Then
      Dim cRow As Integer = 1
      For Each trn As TableRowNode In tn.ChildNodes
            Dim cCell As Integer = 1
            For Each tcn As TableCellNode In trn.ChildNodes
                  Dim pn As ParagraphNode = TryCast(tcn.ChildNodes(0), ParagraphNode)
                  pn.SetText(String.Format("Row {0}, Cell {1}", cRow, cCell))
                  cCell += 1
            Next
            cRow += 1
      Next
End If

Related Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic provides information on how to create text using the xamRichTextEditor from a developer’s perspective.

This topic provides information on how to create hyperlinks using the xamRichTextEditor from the developer’s perspective.

This topic provides information on how to create lists using the xamRichTextEditor from the developer’s perspective.

This topic provides information on how to create images using the xamRichTextEditor from the developer’s perspective.