Document Fields
- 2 minutes to read
Document fields are placeholders added to a document. These fields come with a mechanism that replaces them with corresponding values when the document is rendered for displaying or printing.
A Field is defined by a set of codes that instructs RichEditControl to insert text and graphics into a document automatically. The data inserted into a document when RichEditControl processes a field's codes is called the field result for that field. The process itself is called a field update.
A collection of fields in the document is accessible via the SubDocument.Fields property. A field consists of a Field.CodeRange, containing codes, and a Field.ResultRange containing field results.
To insert a field in a document, use the FieldCollection.Add method. It has two overloads - you can convert a document range to a field or insert a field with the specified codes into the specified position.
The Mail Merge command menu can be used to switch between field display modes - Show All Field Codes or Show All Field Results. Fields can be shown with their codes, placeholders or results. The ShowAllFieldCodesCommand command displays field codes for the entire document, while the ShowAllFieldResultsCommand displays field results. The RichEditCommandId.ToggleFieldCodes switches between placeholders and codes.
RichEditControl provides options specifying whether or not fields are highlighted in the document, together with the highlighting color. They are accessible via the RichEditControlOptionsBase.Fields property of the control's RichEditControlOptionsBase class.
To update the field, use the Field.Update method. An end-user can update a particular field using the corresponding command of the context menu. To update all fields in a document, an end-user can switch on the View Merged Data command button. This operation can also be accomplished by executing the ToggleViewMergedDataCommand or the FieldCollection.Update method.
To help use the Mail Merge feature, RichEditControl provides the RichEditControlOptionsBase.MailMerge options to set the data source for the control. Then, the Document.MailMerge method is used to accomplish the merge. You can also specify different data sources and particular records to merge in the Document.MailMerge method call.
For more information, see the Field Codes section.