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

Replace text between two bookmarks?

1 Answer 89 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Hannah
Top achievements
Rank 2
Hannah asked on 18 Oct 2013, 11:42 PM
I'm sure I might be going about this the wrong way, but here is what I'm trying to accomplish.

My UI has two sides, on the left a user entry form, and on the right a RTB that is formatted to look like a report might.  On load, I define bookmarks to note the start and end of areas.  These start and end bookmarks are to help me identify where to place any updates I'll need to do through code.

When the user types in a value or performs an action on the user entry form, some corresponding changes will need to happen within the RTB document.  I'll need to find the location within the document and perform the update.

Ideally, I can simply identify where I need to select text within the document, delete it, and replace it with whatever.  Also worth noting is that most updates will occur within a Textbox TextChanged event, so speed is a factor as well.

Am I approaching this the right way?  This is my first go with the RTB, and I want to make sure I'm doing things somewhat correct.  lol

Sample range identification:

this.txtCareplanPreview.InsertLineBreak();
this.txtCareplanPreview.InsertBookmark("InterventionNotes" + intItem.CCGInterventionId.ToString());
this.txtCareplanPreview.Insert("Notes: " + intItem.Description);
this.txtCareplanPreview.InsertBookmark("InterventionNotesEnd" + intItem.CCGInterventionId.ToString());
this.txtCareplanPreview.InsertLineBreak();

Update 10/21/2013: I'm attempting to dig into annotations now, but I'm unable to find any good information regarding their usage, either in the documentation or here in the forum.  I believe as this point, annotations are what I'm looking for.  I'd still like some input on how I can best accomplish my goals.
Thanks!

Wayne

1 Answer, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 23 Oct 2013, 06:38 PM
Hello Wayne,

Thank you for writing.

The bookmarks in RadRichTextBox are a good solution for your case. The way bookmarks work is a bit different than you have imagined. Each bookmark has a start and end position which encloses some text. This way each bookmark has text it is associated with. This allows you to select this text and replace it while keeping the bookmark intact. I have attached an example project which demonstrates how this is achieved. In the example I add two lines of text then select each line and add a bookmark that will be associated with the selected text. Then when the text in the two RadTextBoxes changes the corresponding line of code also changes.

I hope this will be useful. Should you have further questions, I would be glad to help.

Regards,
Ivan Petrov
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 >>
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Hannah
Top achievements
Rank 2
Answers by
Ivan Petrov
Telerik team
Share this question
or