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

How to replace all inlineUIContainers in RadDocument by SpanBoxs

2 Answers 122 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
york
Top achievements
Rank 1
york asked on 20 Jan 2013, 10:48 AM
Hi,
I try to replace all inlineUIContainers in RadDocument by SpanBoxes. I know how to do it at caretposition using Delete as,
DocumentPosition currentPosition = radRichTextBox1.Document.CaretPosition;
radRichTextBox1.Document.Delete(false, currentPosition);
radRichTextBox1.Insert(text);

However I am not sure how to get documentpostion for each inlineUIContainers. I need help on this.

Thanks,
York

2 Answers, 1 is accepted

Sort by
0
Christian
Top achievements
Rank 1
answered on 14 Jun 2013, 06:00 AM
Did you figure this out?
I need help for the exact same problem...
0
Boby
Telerik team
answered on 19 Jun 2013, 07:03 AM
Hello Christian, York,
You can achieve this as follows:
this.radRichTextBox.BeginUndoGroup();
 
foreach (var inlineUIContainer in this.radRichTextBox.Document.EnumerateChildrenOfType<InlineUIContainer>().Reverse().ToList())
{
    this.radRichTextBox.Document.CaretPosition.MoveToStartOfDocumentElement(inlineUIContainer);
    this.radRichTextBox.Delete(false);
    this.radRichTextBox.InsertInline(new Span("InlineUIContainer was here."));
}
 
this.radRichTextBox.EndUndoGroup("Replace all InlineUIContainers");
The trick is to iterate the document elements in reversed order to avoid invalidating of the internal document indexes.

Regards,
Boby
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
york
Top achievements
Rank 1
Answers by
Christian
Top achievements
Rank 1
Boby
Telerik team
Share this question
or