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

Delete entire text in rtb programmatically

4 Answers 188 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Karl
Top achievements
Rank 1
Karl asked on 08 Aug 2011, 10:28 AM
Hi,

How do you simply delete the entire content of a richtextbox programmatically?

Thanks,
Karl

4 Answers, 1 is accepted

Sort by
0
Accepted
Stefan
Telerik team
answered on 10 Aug 2011, 04:05 PM
Hello Karl,

Thank you for writing.

RadRichTextBox holds its content in RadDocument. Setting the Document property of RadRichTextBox to a new instance of RadDocument will clear the previous document will its data:
radRichTextBox1.Document = new RadDocument();

I hope that the provided information addresses your question. Should you have any other questions, do not hesitate to contact us.

Kind regards,
Stefan
the Telerik team

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

0
Hannah
Top achievements
Rank 2
answered on 18 Oct 2013, 08:42 PM
I started with that, but then began to wonder if I was introducing any additional memory overhead by creating a new document instead of simply using a "Clear" method of some type.

In my situation, I'm creating an on-the-fly preview of text, and the document will be re-created several times as the user goes from place to place in another part of the screen.  Will I incur unnecessary memory overhead from creating a new document repeatably?

Would it be advisable to create several documents that I'll swap in and out of view as I need them?

Thanks!

Wayne
0
Stefan
Telerik team
answered on 22 Oct 2013, 01:47 PM
Hello Wayne,

In general, the old instance of the Document will not be referenced anywhere and it will be collected by the Garbage Collector when needed, so this should not incur any memory overhead. 

Alternative method to clear a document will be to simply select its content and delete it:
this.radRichTextBox1.Document.Selection.SelectAll();
this.radRichTextBox1.Document.Delete(false);

You can use this one if you prefer.

I hope this helps.

Regards,
Stefan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Hannah
Top achievements
Rank 2
answered on 22 Oct 2013, 06:23 PM
Wonderful!  Thanks!
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Karl
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Hannah
Top achievements
Rank 2
Share this question
or