Bullets.cs
//
// This code is part of Document Solutions for Word demos.
// Copyright (c) MESCIUS inc. All rights reserved.
//
using System;
using GrapeCity.Documents.Word;

namespace DsWordWeb.Demos
{
    // This sample demonstrates how to create a simple bullet list.
    // See the NumberedList sample for how to create a numbered list.
    public class Bullets
    {
        public GcWordDocument CreateDocx()
        {
            GcWordDocument doc = new GcWordDocument();
            var pars = doc.Body.Paragraphs;
            pars.Add("Example of a bullet list with three levels:");

            // A ListTemplate is used to make paragraphs part of a list:
            var myListTemplate = doc.ListTemplates.Add(BuiltInListTemplateId.BulletDefault, "myListTemplate");

            // Action to add a list item:
            Action<string, int> addListItem = (t_, l_) => {
                var 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];
            };

            // Build a bullet list with 3 levels of nesting:
            addListItem("Bullet item 1", 0);
            addListItem("Bullet item 2", 0);
            addListItem("Bullet item 3", 0);
            addListItem("Nested bullet item 1", 1);
            addListItem("Nested bullet item 2", 1);
            addListItem("Double nested bullet item 1", 2);
            addListItem("Double nested bullet item 2", 2);
            addListItem("Nested bullet item 3", 1);
            addListItem("Bullet item 4", 0);

            // Done:
            return doc;
        }
    }
}