Skip to main content

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 field 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.

Field-structure

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.

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. The UpdateFieldsCommand updates field results for all fields in the current selection. To update all fields in a document and display the results, 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.

By default, field results are displayed seamlessly with the document content. However, fields can also be displayed with a shaded background to make them more visible in the document by specifying RichEditControlOptionsBase.Fields options.

See Also