Can't seem to make FieldDisplayMode.DisplayName work correctly

2 posts, 1 answers
  1. Pavel
    Pavel avatar
    32 posts
    Member since:
    Sep 2016

    Posted 29 Nov 2016 Link to this post

    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;
  2. Answer
    Hristo avatar
    1508 posts

    Posted 30 Nov 2016 Link to this post

    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);

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

    Hristo Merdjanov
    Telerik by Progress
    Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
Back to Top