Skip to main content
A newer version of this page is available. .

Numbered and Bulleted Lists

  • 4 minutes to read

XtraRichEdit supports bulleted, numbered and mixed lists.

Numbered and bulleted lists are represented by specific collections of paragraphs. To format lists, use ToggleSimpleNumberingListCommand, ToggleBulletedListCommand and ToggleMultiLevelListCommand commands. List indentation can be specified by executing IncrementIndentCommand or DecrementIndentCommand commands. Numeration in numbering lists can be changed by executing IncrementNumerationFromParagraphCommand and DecrementNumerationFromParagraphCommand commands.

Each paragraph in a document may contain numbering information. Numbering information for a specific paragraph is determined by its Paragraph.ListIndex and Paragraph.ListLevel properties.

The Paragraph.ListIndex property value is the index in the document’s NumberingListCollection. The collection is available via the Document.NumberingLists property.

The collection is composed of items with a NumberingList interface. Each item is an instance of a certain abstract numbering definition, which is represented by AbstractNumberingList interface. A collection of abstract numbering definitions is accessible via the Document.AbstractNumberingLists property.

A Paragraph.ListLevel property of a paragraph indicates its level in the list. To specify formatting for a numbered paragraph, you should modify properties of a corresponding level. Level properties are contained in an object with the ListLevelProperties interface accessible via the NumberingList.Levels property. This change will apply to all paragraphs with a certain level linked to this numbering list. If a property is not specified for the numbering list, the definition for the corresponding level comes from the abstract numbering definition (AbstractNumberingList) linked to a NumberedList.

Bulleted lists are indicated by the NumberingListBase.NumberingType property set to NumberingType.Bullet and the ListLevel.BulletLevel property set to true.

Note

To remove numbering for a particular paragraph, set its ListIndex to -1.

The following code snippet illustrates how to create a multilevel numbered list in a document.

    document.BeginUpdate();
    // Define an abstract list that is the pattern for lists used in the document.
    AbstractNumberingList list = document.AbstractNumberingLists.Add();
    list.NumberingType = NumberingType.MultiLevel;
    // Specify parameters for each list level.
    ListLevel level = list.Levels[0];
    CreateNumberedListHelper.AdjustLevelProperties(level, 150, 75, NumberingFormat.Decimal, "{0}");
    level = list.Levels[1];
    CreateNumberedListHelper.AdjustLevelProperties(level, 300, 150, NumberingFormat.DecimalEnclosedParenthses, "{0}→{1}");
    level = list.Levels[2];
    CreateNumberedListHelper.AdjustLevelProperties(level, 450, 220, NumberingFormat.UpperRoman, "{0}→{1}→{2}");
    // Create a list for use in the document. It is based on a previously defined abstract list with ID = 0.
    document.NumberingLists.Add(0);
    document.EndUpdate();

    document.AppendText("Line one\nLine two\nLine three\nLine four");
    // Convert all paragraphs to list items of level 0.
    document.BeginUpdate();
    ParagraphCollection paragraphs = document.Paragraphs;
    foreach (Paragraph pgf in paragraphs)
    {
        pgf.ListIndex = 0;
        pgf.ListLevel = 0;
    }
    // Specify a different level for a certain paragraph.
    paragraphs[1].ListLevel = 1;
    document.EndUpdate();
class CreateNumberedListHelper {
    public static void AdjustLevelProperties(ListLevel level, int leftIndent, int firstLineIndent, NumberingFormat format, string displayFormat) {
          level.ParagraphProperties.LeftIndent = leftIndent;
        level.ParagraphProperties.FirstLineIndentType = ParagraphFirstLineIndent.Hanging;
        level.ParagraphProperties.FirstLineIndent = firstLineIndent;
        level.Start = 1;
        level.NumberingFormat = format;
        level.DisplayFormatString = displayFormat;
    }
}
See Also