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

Can't seem to make FieldDisplayMode.DisplayName work correctly

1 Answer 60 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Pavel
Top achievements
Rank 1
Pavel asked on 29 Nov 2016, 10:24 PM

I am trying to create a template editor for making letters for mailing.
I open up a new form with a RadRichTextEditor and an Editor Ribbon, and then assign a MailMergeDataSource.ItemsSource.
I add a few fields to the documents, and then use a DocxFormatProvider to get a byte[]
That array goes into an event with a Letter object inside. The event handler code is below.
All I want to do, is reload that byte[] into a different RadRichTextEditor, and then display the mailmerge fields like this <<MyCustomField>> and ideally highlight it. Instead, it's just displaying data from the ItemsSource. Below is the code that I think is relevant

private void LetterEditor_TemplateSaved(object sender, TemplateSavedEventArgs templateSavedEventArgs)
{
    var provider = new DocxFormatProvider();
    var doc = provider.Import(templateSavedEventArgs.Letter.LetterByteArray);
    radRichTextEditor1.Document = doc;
    radRichTextEditor1.Document.ShowMergeFieldsHighlight = true;
    radRichTextEditor1.Document.FieldsDisplayMode = Telerik.WinForms.Documents.Model.FieldDisplayMode.DisplayName;
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 30 Nov 2016, 12:03 PM
Hello Pavel,

Thank you for writing.

Once you load the document in your new RadRichTextEditor instance you need to execute an update command. Please check my code snippet below: 
RadDocument doc = null;
DocxFormatProvider provider = new DocxFormatProvider();
using (Stream intput = File.OpenRead(@"..\..\merged-doc"))
{
    doc = provider.Import(intput);
}
 
this.radRichTextEditor2.Document = doc;
ChangeAllFieldsDisplayModeCommand command = new ChangeAllFieldsDisplayModeCommand(this.radRichTextEditor2.RichTextBoxElement);
command.Execute(FieldDisplayMode.DisplayName);
this.radRichTextEditor2.Focus();

I hope this helps. Please let me know if you need further assistance.

Regards,
Hristo Merdjanov
Telerik by Progress
Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
Tags
RichTextEditor
Asked by
Pavel
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or