Quantcast
Channel: Word for Developers forum
Viewing all articles
Browse latest Browse all 4350

A problem in my code-Regarding bullets and levelled bullets

$
0
0

Hi All,

I have a ribbon button which inserts numbered bullets in my doc like so:

    

private void button4_Click_1(object sender, RibbonControlEventArgs e)
        {

            Word._Document oDoc;
            oDoc = Globals.ThisAddIn.Application.ActiveDocument;
            object oStart = oDoc.Application.Selection.Range.Start;
            object oEnd = oDoc.Application.Selection.Range.End;
             Word.ListGallery listGallery = Globals.ThisAddIn.Application.ActiveDocument.Application.ListGalleries[Word.WdListGalleryType.wdNumberGallery];
             Word.ListFormat listFormat = null;
                  Word.Range rangeInitial = Globals.ThisAddIn.Application.Selection.Range;
                Word.Range range = rangeInitial.Duplicate;
                range.Start = range.End;
                Word.Paragraph oPara;
                 oPara = oDoc.Content.Paragraphs.Add(range);
                 listFormat = oPara.Range.ListFormat;
                this.ApplyListTemplate1(listGallery, listFormat, 1);
                range.ListFormat.ListLevelNumber = 1;
         }

and I have another button which applies levelled numbered bullets like 1.1 ,1.2 etc like this

 private void button5_Click(object sender, RibbonControlEventArgs e)
        {

             Word._Document oDoc;
            oDoc = Globals.ThisAddIn.Application.ActiveDocument;
            object oStart = oDoc.Application.Selection.Range.Start;
            object oEnd = oDoc.Application.Selection.Range.End;


            Word.ListGallery listGallery = Globals.ThisAddIn.Application.ActiveDocument.Application.ListGalleries[Word.WdListGalleryType.wdOutlineNumberGallery];

                Word.Range rangeInitial = Globals.ThisAddIn.Application.Selection.Range;
                Word.Range range = rangeInitial.Duplicate;
                range.Start = range.End;
                Word.Paragraph oPara;
                Word.ListFormat listFormat = null;
                oPara = oDoc.Content.Paragraphs.Add(range);
                  listFormat = oPara.Range.ListFormat;
                this.ApplyListTemplate1(listGallery, listFormat, 2);
                oPara.Range.ListFormat.ListLevelNumber = 2;

            }
Here is my apply list template:  

private void ApplyListTemplate1(Word.ListGallery listGallery, Word.ListFormat listFormat, int level = 2)
        {
            listFormat.ApplyListTemplateWithLevel(
                listGallery.ListTemplates[level],
                ContinuePreviousList: true,
                ApplyTo: Word.WdListApplyTo.wdListApplyToSelection,
                DefaultListBehavior: Word.WdDefaultListBehavior.wdWord10ListBehavior,
                ApplyLevel: level);
        }

 The problem : Here if I click on the level 1 button it inserts a numbered bullet , like "1."  and I click on second btn , it inserts "1.1."  and now if I press the first button to insert "2 ."  it inserts fine,but the second button click does not insert 2.1 ,instead it inserts "1.2" Have been stuck on it for days.Any help is much much appreciated .Thanks                                   


Viewing all articles
Browse latest Browse all 4350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>