# Lists

A list represents a set of properties that describe the appearance and behavior of a set of numbered paragraphs. All lists are stored in the `ListCollection` accessible through the `Lists` property of [RadFlowDocument](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/radflowdocument).

* [List Overview](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/lists#list-overview)

* [List Types](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/lists#list-types)

* [ListLevel Overview](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/lists#listlevel-overview)

* [List Templates](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/lists#list-templates)

* [Create a List](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/lists#create-a-list)

* [Apply List](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/lists#apply-list)

## List Overview

The class that contains the structure corresponding to a list is `List` and exposes the following properties:

* `StyleId`: A string property that specifies the [numbering style](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/styles) associated with the list.

* `Levels`: Represents a collection of [ListLevel](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/lists#listlevel-overview) objects. Every list can contain up to 9 levels.

* `MultilevelType`: The type of the list, described with the [MultilevelType enumeration](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Flow.Model.Lists.MultilevelType.html). It defines the behavior of the list.

> To insert commonly used types of lists like **bullet** or **numbered** lists, [list templates](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/lists#list-templates) can be used.

## List Types

The type of the list is used by an application to determine the user interface behavior for a list and in the `RadWordsProcessing` model is represented by the `MultilevelType` enumeration. The possible types are:

* `HybridMultilevel`: Specifies that the list can contain multiple levels, each from a potentially different type—bullet, decimal, letter, and more. This is the default `MultilevelType` value.

* `Multilevel`: Specifies that the list can contain multiple levels, each of the same type.

* `SingleLevel`: Specifies that only level 1 of the list is used. All other levels are ignored. When a list has `MultilevelType.SingleLevel`, apply the desired list level properties only on the first list level in the `Levels` collection of the `List`.

## ListLevel Overview

[ListLevel](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Flow.Model.Lists.ListLevel.html) is the class containing the structure of the list levels. It describes a set of properties that specify the appearance and behavior of the associated numbered paragraph.

* `StartIndex`: Specifies the starting number of a `ListLevel`. The value must be equal to or greater than 0.

* `RestartAfterLevel`: Indicates the list level which restarts the current level to its start index. The value must be higher (earlier than this level). The possible values are between 0 and 8 inclusive.

* `NumberTextFormat`: Specifies the number format string for a list level.

* `NumberingStyle`: The numbering style of a list level, described with the [NumberingStyle enumeration](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Flow.Model.Lists.NumberingStyle.html). It can be a number, bullet, letter, and more. The default value is `NumberingStyle.Bullet`.

* `IsLegal`: Specifies if all inherited number formats display as `NumberingStyle.Decimal` format. If the value is `true`, all numbering levels in the current `ListLevel` are converted to their corresponding decimal values. If the value is `false`, they display in the string format set by the `NumberTextFormat` property.

* `StyleId`: Specifies the name of the [paragraph style](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/styles) associated with the list level. `ListLevel` can be associated only with a paragraph style.

* `Alignment`: Specifies the alignment of content in this level.

* `CharacterProperties`: Represents the associated [character properties](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/style-properties).

* `ParagraphProperties`: Represents the associated [paragraph properties](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/style-properties).

## List Templates

There are a set of commonly used lists that are predefined for convenience and are called list templates. All available templates are within the [ListTemplateType enumeration](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Flow.Model.Lists.ListTemplateType.html).

To add one of the list templates to the document, pass a `ListTemplateType` value to the `ListCollection.Add()` method. This adds the required template to the document and returns the resulting list.

The following example adds a default bulleted list to a predefined `RadFlowDocument`.

**Example 1: Add the built-in BulletDefault list template to a document**

```C#
List list = document.Lists.Add(ListTemplateType.BulletDefault);
```

## Create a List

The following tutorial walks you through the creation of a list.

1. Define a new `RadFlowDocument` and add a `Section` in it.

   **Step 1: Create a RadFlowDocument and add a Section**

   ```C#
   RadFlowDocument document = new RadFlowDocument();
   Section section = document.Sections.AddSection();
   ```

2. Create a `List` object and associate it with the document by adding it to the `Lists` collection.

   **Step 2: Create a List instance and add it to the document list collection**

   ```C#
   List list = new List();
   document.Lists.Add(list); // Adding the list in the document.
   ```

   In this case, the default `HybridMultilevel` type of list is created.

3. Iterate over the collection of `Levels` the list has.

   **Step 3: Iterate through all available list levels**

   ```C#
   for (int level = 0; level < list.Levels.Count; ++level)
   ```

4. Specify some properties for each level.

   **Step 4: Alternate decimal and bullet numbering styles and set level indentation**

   ```C#
   bool isEven = (level % 2) == 0;

   list.Levels[level].StartIndex = 1;
   //We set Decimal numbering style to a list level if it is even level, otherwise Bullet.
   list.Levels[level].NumberingStyle = isEven ? NumberingStyle.Decimal : NumberingStyle.Bullet;
   //Accordingly to the above rule, we set the corresponding NumberTextFormat.
   list.Levels[level].NumberTextFormat = isEven ? "%" + (level + 1) + "." : "o";
   //Set the desired indentation of the ListLevel can be done through its ParagraphProperties:
   list.Levels[level].ParagraphProperties.LeftIndent.LocalValue = 48 + (level * 24);
   ```

   With this step the list is ready to use.

## Apply List

The tutorial in the [previous section](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/lists#create-a-list) demonstrates how you can create a `List`. After you create the list, you can apply it to a set of [paragraphs](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/paragraph) by setting the `ListId` property of the paragraphs to the `Id` of the list.

The following example demonstrates how you can apply the list created in Steps 1–4.

**Example 6: Create paragraphs for each list level and apply the configured list**

```C#
for (int level = 0; level < list.Levels.Count; level++)
{
    Paragraph paragraph = section.Blocks.AddParagraph();
    paragraph.Inlines.AddRun(string.Format("ListLevel: {0}", level + 1));
    paragraph.ListId = list.Id;
    paragraph.ListLevel = level;
}
```

**Figure 1: Result of Example 6**

![Telerik RadWordsProcessing nested multilevel list showing alternating decimal and bullet numbering across nine list levels](https://www.telerik.com/document-processing-libraries/documentation/assets/15ae7ecd2ccbb00f663dac50cf085d3b/radwordsprocessing_concepts_lists_01.png)

## See Also

* [RadFlowDocument](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/model/radflowdocument)
* [Document Styles](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/styles)
* [Style Properties](https://www.telerik.com/document-processing-libraries/documentation/libraries/radwordsprocessing/concepts/style-properties)
* [Setting Bullet List Indents in RadWordsProcessing](https://www.telerik.com/document-processing-libraries/documentation/knowledge-base/set-bullet-list-indents-radwordsprocessing)
