none
How to insert levelled bullets with my current code snippet? RRS feed

  • Question

  • Hi All,

    I have two buttons, one which inserts level 1 bullets and another which inserts level 2 bullets 

     The problem : Here if I click on the level 1 button it inserts a numbered bullet , like "1."  and I click on second button , 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      

    This is what I have tried so far,

        //to insert level -1 numbered bullets

    private void button4_Click_1(object sender, RibbonControlEventArgs e)
            {
       Word.ListGallery listGallery = Globals.ThisAddIn.Application.ActiveDocument.Application.ListGalleries[Word.WdListGalleryType.wdOutlineNumberGallery];
                     oPara = oDoc.Content.Paragraphs.Add(range);
                     listFormat = oPara.Range.ListFormat;
                    this.ApplyListTemplate1(listGallery, listFormat, 1);
                    range.ListFormat.ListLevelNumber = 1;
             }

    //to insert level-2 bullets (1.1,,2.1 etc )

     private void button5_Click(object sender, RibbonControlEventArgs e)
            {

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

                    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);
            }

                                  
    Saturday, October 18, 2014 4:28 AM

Answers

  • Hi Apoorva

    Use these two commands "indent" and "outdent" a multilevel list.

        Selection.Range.ListFormat.ListIndent
        Selection.Range.ListFormat.ListOutdent
    

    Hope this helps


    Kind Regards, Rich ... http://greatcirclelearning.com

    Monday, October 20, 2014 2:49 PM

All replies

  • Hi Apoorva

    Use these two commands "indent" and "outdent" a multilevel list.

        Selection.Range.ListFormat.ListIndent
        Selection.Range.ListFormat.ListOutdent
    

    Hope this helps


    Kind Regards, Rich ... http://greatcirclelearning.com

    Monday, October 20, 2014 2:49 PM
  • Thank you very much Rich :) this method did work,not only that it removed a lot more bugs that I was facing, thanks a lot.. 
    Monday, October 20, 2014 4:24 PM