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

DocumentVariables in imported doc

1 Answer 53 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Sergey
Top achievements
Rank 1
Sergey asked on 08 Jul 2014, 10:54 AM
Hello!

I want to use variables in the middle of the imported rtf document.

When I write:
RtfBox.InsertField(new DocumentVariableField() { VariableName = "Name" }, FieldDisplayMode.Code);
field appears at the beginning of the document.

Is there any way to force field to appear at concrete place?



1 Answer, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 09 Jul 2014, 04:27 PM
Hello Sergey,

All of RadRichTextBox's Insert~() methods work with the caret position (or document selection if such is available). By default when you load a document the caret is located at the first position in the document which is most likely the cause of the behavior you are observing.

The DocumentPosition class exposes a set of handy methods which allow you to move the caret programmatically. For example, the next code snippet would move the caret at the end of the document and allow you to insert content there.
RtfBox.Document.CaretPosition.MoveToLastPositionInDocument();
     RtfBox.InsertField(new DocumentVariableField() { VariableName = "Name" }, FieldDisplayMode.Code);

I hope this helps.

Regards,
Petya
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
RichTextBox
Asked by
Sergey
Top achievements
Rank 1
Answers by
Petya
Telerik team
Share this question
or