Loading multiple RadDocuments into a RichTextBox

4 posts, 0 answers
  1. Doug
    Doug avatar
    6 posts
    Member since:
    Oct 2010

    Posted 14 Mar 2011 Link to this post

    Is there a way to import more than one RadDocument into a RichTextBox control in code?

    Also what is the easiest way to insert text into a RadDocument in code (to put a timestamp at the footer or something like that) ?

    Thank you,

    Doug
  2. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 17 Mar 2011 Link to this post

    Hi Doug,

    You can have only one document in RadRichTextBox. If you have several files, you can import them into separate documents and then "merge" them into one as described in the the last post in this forum thread
    If you would like to insert a smaller piece of text at a random position in a document, you can use the rich text box's Insert method, which inserts text at the current caret position with the style of the span at the place in the document where you insert the text. If you like, you can also use the InsertInline method and pass a new Span as a parameter. You can set the span's Text and customize its style.

    You can also manipulate the caret position before invoking the insert methods in order to change the position where you wish the text to appear. You can find more information on document positions and their usage here.
    If you need further assistance, do not hesitate to get back to us.

    Best wishes,
    Iva
    the Telerik team
  3. Vinicius
    Vinicius avatar
    9 posts
    Member since:
    Dec 2011

    Posted 27 Jan 2012 Link to this post

    Hi there,
    Im loading a richtextbox with a docx using this code:

                DocxFormatProvider docxProvider = new DocxFormatProvider();
                RadDocument document = docxProvider.Import(Resources.RichTextBox_for_WinForms);
                this.radRichTextBox1.Document = document;

    I would like to know if i can append more than one file like this to the same richtextbox, is that possible?
  4. Boby
    Admin
    Boby avatar
    685 posts

    Posted 01 Feb 2012 Link to this post

    Hi Vinicius,
    You can use the DocumentFragment class to merge multiple documents and set the result to an instance of RadRichTextBox:
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        // you can use other format providers as well
        TxtFormatProvider provider = new TxtFormatProvider();
      
        List<RadDocument> documents = new List<RadDocument>()
        {
            // this will create some test documents that will be merged
            provider.Import("text 1"),
            provider.Import("text 2"),
            provider.Import("text 3"),
        };
      
        RadDocument mergedDocument = new RadDocument();
        foreach (var document in documents)
        {
            mergedDocument.CaretPosition.MoveToLastPositionInDocument();
            mergedDocument.InsertFragment(new DocumentFragment(document));
        }
          
        // set the document to RadRichTextBox
        this.radRichTextBox.Document = mergedDocument;
    }

    Don't hesitate to contact us if you have other questions.

    Regards,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top