NumberedList.vb
''
'' This code is part of Document Solutions for Word demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports GrapeCity.Documents.Word

'' This sample demonstrates how to create a numbered list
'' with three levels.
'' See the Bullets sample for how to create a bullet list.
Public Class NumberedList
    Function CreateDocx() As GcWordDocument
        Dim doc = New GcWordDocument()

        Dim pars = doc.Body.Paragraphs
        pars.Add("A numbered list with 3 levels:")
        '' A ListTemplate is used to make paragraphs part of a list:
        Dim myListTemplate = doc.ListTemplates.Add(BuiltInListTemplateId.NumberDefault, "myListTemplate")

        '' Function to add a list item:
        Dim addItem As Action(Of String, Integer) =
            Sub(t_, l_)
                Dim p_ = pars.Add(t_)
                '' This makes a paragraph a list item:
                p_.ListFormat.Template = myListTemplate
                '' Set the item's nesting level (first level is 0):
                p_.ListFormat.LevelNumber = l_
                '' This ensures item spacing consistent with MS Word
                p_.Style = doc.Styles(BuiltInStyleId.ListParagraph)
            End Sub

        '' Create a 3-level numbered nested list:
        addItem("Top item 1", 0)
        addItem("Top item 2", 0)
        addItem("Top item 3", 0)
        addItem("Nested item 1", 1)
        addItem("Nested item 2", 1)
        addItem("Double nested item 1", 2)
        addItem("Double nested item 2", 2)
        addItem("Double nested item 3", 2)
        addItem("Nested item 3", 1)
        addItem("Nested item 4", 1)
        addItem("Top item 4", 0)
        addItem("Top item 5", 0)

        '' Done:
        Return doc
    End Function
End Class