MergeField format editing

4 posts, 0 answers
  1. Guy
    Guy avatar
    18 posts
    Member since:
    Oct 2012

    Posted 17 Apr 2013 Link to this post

    Hi

    I am inserting MergeFields into a RadDocument and at a later stage performing a mail merge. I see that the MergeField class has DateTimeFormatting, GeneralFormatting and NumericFormatting properties, but I don't see any way to modify these formats during the document creation by the user. Without the ability for the user to change these settings, values are merged into the document in a general format. I'd like to be able to give the user the option to change the date format and number formats within the editor.

    How would this be accomplished using RadRichTextBox?

    Thanks,

    Guy
  2. Petya
    Admin
    Petya avatar
    975 posts

    Posted 19 Apr 2013 Link to this post

    Hello Guy,

    The properties you are referring to are mostly used internally or when implementing a custom field. Moreover, I am not quite sure how exactly you want them to change the merge field in your document, so can you please elaborate a bit on what exactly you are trying to achieve.

    I'm looking forward to your reply.
     
    Kind regards,
    Petya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Guy
    Guy avatar
    18 posts
    Member since:
    Oct 2012

    Posted 22 Apr 2013 Link to this post

    Hi

    Yes this is using custom fields. For example, the data object has a double field which the user can then merge into their document. But the need to be able to choose how the double is formatted (decimal places, thousand separators, etc). In the standard interface there was no way to do this.

    I solved this by subscribing to the document.CaretPosition.PositionChanged event, and in the handler checking whether the caret is on a field or not. If it is on a field, I get the field properties and update a custom UI element that I embed into the toolbar which allows the user to set the field's NumericFormatting and DateTimeFormatting properties.

    I am busy applying the same idea to picture fields, because when you merge a picture field, there is no way to specify the maximum/minimum size of the image, so it relies on the size of the source image. When the source image can be any size, it can really destroy the layout of the document.

    Thanks,

    Guy
  5. Alex
    Admin
    Alex avatar
    129 posts

    Posted 24 Apr 2013 Link to this post

    Hi,
    Indeed there is currently no way to configure the formatting switches form the UI. The user can additionally add those switches by modifying the code of the field. The switches are the following:
    • \@ for DateTimeFormatting (will be applied if the MailMerge value is DateTime).
    • \# for NumericFormatting (will be applied if the MailMerge value is a number).
    • \* for GeneralFormatting.
    Adding those switches while field is in the code mode is the same as setting the equivalent properties of the field. So for example is the code of the field is "{MERGEFIELD DateOfBirth \@ dd.MM.yyyy}" the "dd.MM.yyyy" value will be assigned to the DateTimeFormatting property of the field and it will be used if the value is DateTime.

    Your approach for setting this values - with addition UI is correct. However, there is no "size" switch for the picture fields. You can either assure that the images are not to big inside the mail merge source, or modify they size after the field have been updated.

    Please don't hesitate to contact us again of you have more questions.

    Kind regards,
    Alex
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top