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

Disable editing MergeField content.

3 Answers 15 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Jakub
Top achievements
Rank 1
Iron
Jakub asked on 18 Oct 2018, 08:33 AM

Hi,

it is possible to prevent user from chaning merge fields content using RadRichTextBox. I know this changes are saving or affects document, but it looks not good when user can change {MERGEFIELD NAME} to something like {MERREAF52FF AAME} or anything else. Is there any flag for this? Or should I implement my own function? How to check if current caret position is inside merge field?

 

Thanks

3 Answers, 1 is accepted

Sort by
0
Jakub
Top achievements
Rank 1
Iron
answered on 18 Oct 2018, 11:04 AM
[quote]Jakub said:

I know this changes are saving or affects document[/quote]

Sory, mistake, should be: I know this changes aren't changing merge fields or affects document.

0
Accepted
Tanya
Telerik team
answered on 23 Oct 2018, 08:26 AM
Hi Jakub,

To prevent the modification of a field, you will need to implement a custom solution that doesn't allow the end users to modify the fields. You can determine whether the current caret position is inside a merge field using the inline the position is at. Here is how that would look like in code:
Inline currentInline = this.radRichTextBox.Document.CaretPosition.GetCurrentInline();
FieldRangeStart fieldStart = currentInline.FieldStart as FieldRangeStart;
if (fieldStart != null && fieldStart.Field is MergeField)
{
    // The caret position is indide a MergeField
}

Such a flag or functionality is not available in the control and in the specification of the Open XML format. Depending on the projects' needs, you could use ReadOnlyRanges. What you should have in mind if you take this approach is that when the protection is applied, will not allow updating the field and these objects are serialized to XAML only.

Hope this is helpful.

Regards,
Tanya
Progress Telerik
Get quickly and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jakub
Top achievements
Rank 1
Iron
answered on 23 Oct 2018, 11:27 AM

Thank you Tanya! This piece of code is exactly what I need.

Best regards

Tags
RichTextBox
Asked by
Jakub
Top achievements
Rank 1
Iron
Answers by
Jakub
Top achievements
Rank 1
Iron
Tanya
Telerik team
Share this question
or