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

RTF table borders lost on import

2 Answers 87 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 20 Feb 2013, 05:21 PM
I am trying to build a RadDocument from multiple RTF strings. Tables are imported correctly except the borders are lost. The borders displayed correctly when viewed in MS Word. Is there a better way to do this?

foreach (string rtfTextString in myListOfStrings)
{
    RtfFormatProvider provider = new RtfFormatProvider();
    RadDocument  subDoc = provider.Import(rtfTextString);
  
    foreach (Section s in subDoc.Sections)
    {
        var copy = s.CreateDeepCopy() as Section;
        if (copy != null)
        {
            richTextBox.Document.Sections.Add(copy);
        }
    }
}

2 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 21 Feb 2013, 04:37 PM
Nevermind. I found the posts about InsertFragment. I had tried that before, but got null reference exceptions. Then I saw a post about having to Measure and Arrange before calling InsertFragment.

MeasureAndArrangeInDefaultSize(doc);
  
doc.CaretPosition.MoveToLastPositionInDocument();
doc.InsertFragment(new DocumentFragment(subDoc));

Now it works great. You should add the bit about Measure and Arrange to your documentation.
0
Accepted
Petya
Telerik team
answered on 25 Feb 2013, 01:08 PM
Hello John,

I am glad you were able to resolve the issue you were facing.

Generally, the latter approach - inserting a document fragment, is the recommended one as creating deep copies of sections and adding them to a measured document (in that case - the one shown in the editor) using the Sections collection might cause issues.

As for your comment about the exception you were observing - I was unable to reproduce it. However, you should indeed call the method when creating a document from code prior to inserting in it. 

Let us know if you need further assistance.
 
Kind regards,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Petya
Telerik team
Share this question
or