This is a migrated thread and some comments may be shown as answers.

Loading multiple RadDocuments into a RichTextBox

3 Answers 259 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Doug
Top achievements
Rank 1
Doug asked on 14 Mar 2011, 08:03 PM
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

3 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 17 Mar 2011, 06:03 PM
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
0
Vinicius
Top achievements
Rank 1
answered on 27 Jan 2012, 07:57 PM
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?
0
Boby
Telerik team
answered on 01 Feb 2012, 09:13 AM
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 >>

Tags
RichTextBox
Asked by
Doug
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Vinicius
Top achievements
Rank 1
Boby
Telerik team
Share this question
or