Removing Section/blocks from a RadDocument

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

    Posted 14 Apr Link to this post


    I have a uerControl, MyUserControl, that contains a RadRichTextEditor. The method that initializes MyUserControl instantiates a new RadDocument for the RadRichTextEditor. The new document is sometimes empty (no sections) and sometimes has one section that contains a paragrph!!! I have the following code to remove the initial paragraph (2 versions) and they both crash. What is the right way of doing it?

    public void InitMyUserControl()
         textEditor.RichTextBoxElement.BackColor = Color.White;
          textEditor.Document = new RadDocument();
          if ( textEditor.Document.Sections.Count != 0)
                var block =  textEditor.Document.Sections.First.Blocks.First;


          if ( textEditor.Document.Sections.Count != 0)
                Section section =  textEditor.Document.Sections.First;



  2. Hristo Merdjanov
    Hristo Merdjanov avatar
    711 posts

    Posted 15 Apr Link to this post

    Hi Shahrzade,

    Thank you for writing.

    Deleting the sections or blocks in this manner leaves the editor in an invalid state. In order to accomplish your task, you can call the Clear method of the Blocks and Sections collections respectively:

    In case, you would like to delete the contents of the editor you can perform a selection and then clear the contents:

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Hristo Merdjanov
    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