Skip to main content
All docs
V25.1
  • Paragraph.AddToListAsync(List, Int32, CancellationToken) Method

    Adds the paragraph to a list.

    Namespace: DevExpress.Blazor.RichEdit

    Assembly: DevExpress.Blazor.RichEdit.v25.1.dll

    NuGet Package: DevExpress.Blazor.RichEdit

    Declaration

    public ValueTask<bool> AddToListAsync(
        List list,
        int listLevelIndex = 0,
        CancellationToken cancellationToken = default(CancellationToken)
    )

    Parameters

    Name Type Description
    list List

    A list to which the paragraph is added.

    Optional Parameters

    Name Type Default Description
    listLevelIndex Int32 0

    A list level to which the paragraph is added.

    cancellationToken CancellationToken null

    An object that propagates a cancellation notification.

    Returns

    Type Description
    ValueTask<Boolean>

    A structure that stores an awaitable result of an asynchronous operation. The awaitable result is true if the operation ends successfully; otherwise, it is false.

    Remarks

    A list in a document is a series of paragraphs. Each paragraph contains information about the list (ListIndex) and the list level (ListLevelIndex) to which it belongs, if any.

    Call the AddToListAsync method to set the ListIndex and ListLevelIndex properties, apply a list format style to the paragraph, and add the paragraph to the list.

    <DxRichEdit @ref="richEdit" />
    
    @code {
        DxRichEdit richEdit;
        Document documentAPI;
        @* ... *@
        /* Surround the code that contains an asynchronous operation with a try-catch block to handle
        the OperationCanceledException. This exception is thrown when an asynchronous operation is canceled. */
            try {
                documentAPI = richEdit.DocumentAPI;
                @* ... *@
                List numberedList = await documentAPI.Lists.CreateAsync(ListType.Number);
                await documentAPI.AddTextAsync("Paragraph 1");
                Paragraph par1 = await documentAPI.Paragraphs.GetAsync(0);
                await par1.AddToListAsync(numberedList);
                Paragraph par2 = await documentAPI.Paragraphs.CreateAsync();
                await documentAPI.AddTextAsync("Paragraph 2");
                await par2.AddToListAsync(numberedList,1);
                Paragraph par3 = await documentAPI.Paragraphs.CreateAsync();
                await documentAPI.AddTextAsync("Paragraph 3");
                await par3.AddToListAsync(numberedList,1);
                Paragraph par4 = await documentAPI.Paragraphs.CreateAsync();
                await documentAPI.AddTextAsync("Paragraph 4");
                await par4.AddToListAsync(numberedList);
                Paragraph par5 = await documentAPI.Paragraphs.CreateAsync();
                await documentAPI.AddTextAsync("Paragraph 5");
                await par5.AddToListAsync(numberedList);
                @* ... *@
            }
            catch (OperationCanceledException e) {
                Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
            }
    }
    

    The image below shows the result.

    Rich Edit - List

    Call the RemoveFromListAsync(CancellationToken) method to remove the paragraph from the list.

    await par5.RemoveFromListAsync();
    

    Rich Edit - Remove a Paragraph from List

    See Also