Click or drag to resize

ListFormat Class

Represents list format which shall be applied to the contents of the parent paragraph.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentFormat
    SautinSoft.DocumentListFormat

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.4.24
Syntax
public sealed class ListFormat : Format

The ListFormat type exposes the following members.

Constructors
 NameDescription
Public methodCode exampleListFormat Initializes a new instance of the ListFormat class.
Top
Properties
 NameDescription
Public propertyIsList Gets a value indicating whether this ListFormat defines the list.
Public propertyCode exampleListLevelFormat Gets the list level formatting and any formatting overrides applied to the current paragraph.
Public propertyCode exampleListLevelNumber Gets or sets the list level number (0 to 8) for the paragraph.
Public propertyCode exampleStyle Gets or sets the ListStyle.
Top
Methods
 NameDescription
Public methodClearFormatting Clears the formatting.
(Overrides FormatClearFormatting)
Public methodEquals Determines whether the specified object is equal to this ListFormat instance.
(Overrides ObjectEquals(Object))
Top
Example

See Developer Guide: How to create multilevel ordered and unordered lists

How to create multilevel ordered and unordered lists in C#
using SautinSoft.Document;

namespace Sample
{
    class Sample
    {

        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            MultilevelLists();
        }

        /// <summary>
        /// How to create multilevel ordered and unordered lists.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/create-multilevel-list-in-docx-document-net-csharp-vb.php
        /// </remarks>        
        public static void MultilevelLists()
        {
            string documentPath = @"MultilvelLists.docx";

            // Let's create a new document.
            DocumentCore dc = new DocumentCore();

            // Add a new section.
            Section s = new Section(dc);
            dc.Sections.Add(s);

            string[] myCollection = new string[] { "One", "Two", "Three", "Four", "Five" };

            // Create list style.
            ListStyle ls = new ListStyle("MyListDot", ListTemplateType.NumberWithDot);
            dc.Styles.Add(ls);

            // Add the collection of paragraphs marked as ordered list.
            int level = 0;
            foreach (string listText in myCollection)
            {
                Paragraph p = new Paragraph(dc);
                dc.Sections[0].Blocks.Add(p);

                p.Content.End.Insert(listText, new CharacterFormat() { Size = 14.0, FontColor = Color.Black });
                p.ListFormat.Style = ls;
                p.ListFormat.ListLevelNumber = level++;
                p.ParagraphFormat.SpaceAfter = 0;
            }

            // Add the collection of paragraphs marked as unordered list (bullets).
            // Create list style.
            ListStyle ls1 = new ListStyle("MyListBullet", ListTemplateType.Bullet);
            dc.Styles.Add(ls1);

            level = 0;
            foreach (string listText in myCollection)
            {
                Paragraph p = new Paragraph(dc);
                dc.Sections[0].Blocks.Add(p);

                p.Content.End.Insert(listText, new CharacterFormat() { Size = 14.0, FontColor = Color.Black });
                p.ListFormat.Style = ls1;
                p.ListFormat.ListLevelNumber = level++;
                p.ParagraphFormat.SpaceAfter = 0;
            }

            // Save our document into DOCX file.
            dc.Save(documentPath, new DocxSaveOptions());

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath) { UseShellExecute = true });
        }
    }
}
How to create multilevel ordered and unordered lists in VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        MultilevelLists()
    End Sub
    ''' Get your free 30-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' How to create multilevel ordered and unordered lists.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/create-multilevel-list-in-docx-document-net-csharp-vb.php
    ''' </remarks>
    Sub MultilevelLists()
        Dim documentPath As String = "MultilvelLists.docx"

        ' Let's create a new document.
        Dim dc As New DocumentCore()

        ' Add a new section.
        Dim s As New Section(dc)
        dc.Sections.Add(s)

        Dim myCollection() As String = {"One", "Two", "Three", "Four", "Five"}

        ' Create list style.
        Dim ls As New ListStyle("MyListDot", ListTemplateType.NumberWithDot)
        dc.Styles.Add(ls)

        ' Add the collection of paragraphs marked as ordered list.
        Dim level As Integer = 0
        For Each listText As String In myCollection
            Dim p As New Paragraph(dc)
            dc.Sections(0).Blocks.Add(p)

            p.Content.End.Insert(listText, New CharacterFormat() With {
                .Size = 14.0,
                .FontColor = Color.Black
            })
            p.ListFormat.Style = ls
            p.ListFormat.ListLevelNumber = level
            level += 1
            p.ParagraphFormat.SpaceAfter = 0
        Next listText

        ' Add the collection of paragraphs marked as unordered list (bullets).
        ' Create list style.
        Dim ls1 As New ListStyle("MyListBullet", ListTemplateType.Bullet)
        dc.Styles.Add(ls1)

        level = 0
        For Each listText As String In myCollection
            Dim p As New Paragraph(dc)
            dc.Sections(0).Blocks.Add(p)

            p.Content.End.Insert(listText, New CharacterFormat() With {
                .Size = 14.0,
                .FontColor = Color.Black
            })
            p.ListFormat.Style = ls1
            p.ListFormat.ListLevelNumber = level
            level += 1
            p.ParagraphFormat.SpaceAfter = 0
        Next listText

        ' Save our document into DOCX file.
        dc.Save(documentPath, New DocxSaveOptions())

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(documentPath) With {.UseShellExecute = True})
    End Sub

End Module
See Also