Problem with mailMarge in RadRichTextBox

4 posts, 0 answers
  1. Jan
    Jan avatar
    2 posts
    Member since:
    Feb 2014

    Posted 14 Jun Link to this post

    I have two problems and a question concerning RadRichTextBox:

    Problem 1: I have imported (with RtfFormatProvider ) an RTF document (Word RTF ) to RadRichTextBox. This document contains a header with merge fields. Also some other merge fields in the “body” of the document. I have also attached a merge collection with some dummy data to the document. When the document is opened in RadRichTextBox then the merge fields in the head are already mailMerge’ed. The merge fields that are not in the head is not mailMerge’ed . What to do, to avoid that mailmerg are not be performed in the header of the document when open in RadRichTextBox?

    Problem 2: Same RTF document (Word RTF) as above. In the head, there is a TAB between the merge fields, but the distance between the merge fields are shorter when the document is imported into RadRichTextBox than when it is open in Word. The rest of the document, look like the same. What should I do to change TAB space in the header?

    One question: When it have completed a Mailmerge (test mailmarge). Can I undo (with code) the Mailmerge? I just want to be able to test Mailmerge, that it was correct and then recover the document as it was before the Mailmerge, and also if I have added some text after the Mailmerge or something else like change text till bold. The recovered file should also contain the changes after the mailmarge.

  2. Todor
    Admin
    Todor avatar
    168 posts

    Posted 15 Jun Link to this post

    Hi Jan,

    I'll go straight to your issues:

    1. I've tried to reproduce the different behavior of fields displaying between the header and the main body of a document, but to no avail. I've created such a document with RadRichTextBox and import it back there and everything works as expected. I've tried the same with MS Word and everything looks OK again. You can find the documents attached.

    2. I can confirm there is difference between the tab stops which are defined in a paragraph which is in header/footer in MS Word and those in RadRichTextBox. Actually, in RadRichTextBox, there aren't such tab stops declared and thus when a tab is inserted, the position is moved with the default tab stop width. I've added this feature request in our backlog and here is the related item in our feedback portal for which you could vote and subscribe.

    About your last question - performing mail merge is not an undoable operation and thus you cannot perform undo on it.

    If you need further assistance, please get back to us again.

    Regards,
    Todor
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jan
    Jan avatar
    2 posts
    Member since:
    Feb 2014

    Posted 22 Jun in reply to Todor Link to this post

    Hi Todor and thanks for your answer!

    The problem 1, it was wrong about the merge fields in the header, they have not been merge.

    But the problem is another. When I open the document with dummy merge data, the dummy data will appear (Result) in the merge fields in the header instead of the merge field name (DisplayName). While the merge fields in the document body show the name for the merge field instead.

    I have tried to change the merge fields in the header to display the name, when the document is opened, but merge fields still show the dummy data.

    Once the document is open, I can open up the header with button (EditHeaderCommand) and then show the name merge fields with a button (ChangeAllFieldsDisplayModeCommand and Result).

    What to do, to show the merge name instead for data in the merge field in the header when the document is opened?
  5. Todor
    Admin
    Todor avatar
    168 posts

    Posted 24 Jun Link to this post

    Hi Jan,

    To change a field's display mode, you could use the ChangeAllFieldsDisplayMode() method, where you have to pass FieldDisplayMode.DisplayName as a parameter. For example, to achieve this in your scenario, you could attach to the RadRichTextBox's DocumentChanged event and to set the mail merge data source and to invoke the mentioned method in the event handler:
    private void radRichTextBox_DocumentChanged(object sender, EventArgs e)
    {
        this.radRichTextBox.Document.MailMergeDataSource.ItemsSource = // Set the data source
        this.radRichTextBox.ChangeAllFieldsDisplayMode(FieldDisplayMode.DisplayName);
    }

    For your convenience, I've created a sample demo project which illustrates the above described approach. You can find it attached.

    If you have further questions or any feedback, do not hesitate to get back to us again.

    Regards,
    Todor
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top