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

MergeField format editing

3 Answers 147 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Guy
Top achievements
Rank 2
Guy asked on 17 Apr 2013, 07:43 AM
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

3 Answers, 1 is accepted

Sort by
0
Petya
Telerik team
answered on 19 Apr 2013, 02:34 PM
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.

0
Guy
Top achievements
Rank 2
answered on 22 Apr 2013, 08:12 AM
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
0
Alex
Telerik team
answered on 24 Apr 2013, 12:29 PM
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.

Tags
RichTextBox
Asked by
Guy
Top achievements
Rank 2
Answers by
Petya
Telerik team
Guy
Top achievements
Rank 2
Alex
Telerik team
Share this question
or