numbered list

2 posts, 0 answers
  1. Shahrzade
    Shahrzade avatar
    8 posts
    Member since:
    Feb 2016

    Posted 15 Apr Link to this post

    Hi,

    I am trying to build a RadDocument from many input RadDocuments (to put together many small documents). Many of these smaller documents have numbered lists whose numbering should be preserved. To insert each of the small documents, I am using
         richTextEditorToInsertInto.DocumentEditor.InsertFragment(new DocumentFragment(radDocumentToAppend))

    When put together in the bigger document the numbering continues to increase, e.g., if

    Document_1 contains:      and       Document_2 contains:
      DOC1_Header                               DOC2_Header
          1.  Doc1_Item1                               1.  Doc2_Item1
          2.  Doc1_Item2                               2.  Doc2_Item2
          3.  Doc2_Item3                               3.  Doc2_Item3
    When put together, the resulting document contains
        DOC1_Header 
          1.  Doc1_Item1
          2.  Doc1_Item2
          3.  Doc2_Item3
        DOC2_Header
          4.  Doc2_Item1
          5.  Doc2_Item2
          6.  Doc2_Item3

    Is there a way of resetting the start index for list numbering to 1? How can i keep the numbering from the original documents?

    Thanks,

    Shahrzade.

  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 18 Apr Link to this post

    Hello Shahrzade,

    Thank you for writing.

    Here is a sample code snippet demonstrating how to insert two numbered lists with reset start index: 
    public Form1()
    {
        InitializeComponent();
        
        RadDocument doc1 = new RadDocument();
        Section section = new Section();
        for (int i = 1; i <= 3; i++)
        {
            Paragraph item1 = new Paragraph();   
            Span span = new Span("Doc1_Item" + i);
            item1.Inlines.Add(span);
            section.Blocks.Add(item1);
        }
       
        doc1.Sections.Add(section);          
        this.radRichTextEditor1.DocumentEditor.InsertFragment(new DocumentFragment(doc1));
     
        DocumentPosition startPosition = this.radRichTextEditor1.Document.CaretPosition; 
        DocumentPosition endPosition = new DocumentPosition(startPosition);
        startPosition.MoveToFirstPositionInDocument();
        endPosition.MoveToLastPositionInDocument();
        this.radRichTextEditor1.Document.Selection.AddSelectionStart(startPosition);
        this.radRichTextEditor1.Document.Selection.AddSelectionEnd(endPosition);
        
        ListStyle newlistStyle = new ListStyle(DefaultListStyles.Numbered);
        
        this.radRichTextEditor1.ChangeListStyle(newlistStyle);
                    this.radRichTextEditor1.Document.Selection.Clear();
     
        startPosition = this.radRichTextEditor1.Document.CaretPosition;
        startPosition.MoveToLastPositionInDocument();                   
        startPosition = new DocumentPosition(this.radRichTextEditor1.Document.CaretPosition);
        
        RadDocument doc2 = new RadDocument();
        Section section2 = new Section();
        for (int i = 1; i <= 3; i++)
        {
            Paragraph item1 = new Paragraph();   
            Span span = new Span("Doc2_Item" + i);
            item1.Inlines.Add(span);
            section2.Blocks.Add(item1);
        }
        doc2.Sections.Add(section2);
        this.radRichTextEditor1.DocumentEditor.InsertFragment(new DocumentFragment(doc2));
        
        startPosition.MoveToFirstPositionInDocument();
        for (int i = 0; i < doc1.Sections.First().Blocks.Count; i++)
        {
            startPosition.MoveToFirstPositionInNextParagraph();
        }
         
        this.radRichTextEditor1.Document.Selection.AddSelectionStart(startPosition);
        this.radRichTextEditor1.Document.Selection.AddSelectionEnd(endPosition);
         
     
        ListStyle listStyle = new ListStyle(DefaultListStyles.Numbered);
        this.radRichTextEditor1.ChangeListStyle(listStyle);  
        this.radRichTextEditor1.Document.CaretPosition.MoveToPosition(startPosition);
        this.radRichTextEditor1.RestartListNumbering();  
        this.radRichTextEditor1.Document.Selection.Clear();
    }

    I hope this information helps. Should you have further questions I would be glad to help.

     Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top