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

Append document from one control to another

1 Answer 82 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Abraham
Top achievements
Rank 1
Abraham asked on 13 Mar 2013, 04:03 AM
I have two Telerik rich text boxes in my winforms application. I am trying to append the formatted text from one of the rich textboxes to all areas where a predefined section in the first rich textbox. 

The below code works for finding the required predefined  sections - Once this is done, There was an option to insert a text but I couldnt find anything where I could insert the formatted text. 

radRichTextBox1.Document.Selection.Clear();

 

DocumentTextSearch search = new DocumentTextSearch(radRichTextBox1.Document);

 

foreach (var textRange in search.FindAll("Section1"))

{

radRichTextBox1.Document.Selection.AddSelectionStart(textRange.StartPosition);

 

 

this.radRichTextBox1.Document.Selection.AddSelectionEnd(textRange.EndPosition);

// what to do here to insert the formattted text from radRichTextBox2

}

1 Answer, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 13 Mar 2013, 11:51 AM
Hi Abraham,

Thank you for writing.

Here is how you can append (insert) the selected formatted text from the first RadRichTextBox control to the sections that you want in the second control:
private void radButton1_Click(object sender, EventArgs e)
{
    DocumentFragment selectedFragment = radRichTextBox1.Document.Selection.CopySelectedDocumentElements();
 
    DocumentTextSearch search = new DocumentTextSearch(radRichTextBox2.Document);
    foreach (var textRange in search.FindAll("RichTextBox"))
    {
        radRichTextBox2.Document.CaretPosition.MoveToPosition(textRange.EndPosition);
        radRichTextBox2.Document.InsertFragment(selectedFragment);
    }
}

I hope that you find this information useful.
 

Regards,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Abraham
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or