Back to Devexpress

Document Fields

aspnet-117652-components-rich-text-editor-document-document-model-document-fields.md

latest5.4 KB
Original Source

Document Fields

  • Jun 17, 2021
  • 4 minutes to read

Overview

Document fields are special placeholders for non-static data that might change (be updated on field updates). These placeholders are replaced with actual data when the document is rendered for printing or fields are updated directly. Using fields, you can automate different aspects of your document, such as auto page numbering, inserting actual dates and times, etc.

A field is defined by a set of codes that instructs the RichEdit to insert text and graphics into a document automatically. The RichEdit processes field codes and inserts data in the field. The inserted data is called the field result. The process itself is called a field update.

Field Structure

In the text buffer, a field is represented as the following string structure containing five main parts.

{Code}Result>

  • Open symbol ( { )
  • Code part
  • Separator symbol ( } )
  • Result part
  • End symbol ( > )

The value of the Result part is created dynamically depending on the Code part type when the field update process is initiated (through the F9 key or the corresponding command in the ribbon or context menu). When the RichEdit opens a document, document fields are not updated.

The Code part has the following syntax.

FIELDNAME Properties Optional_Switches

  • FIELDNAME

  • Properties

  • Optional switches

For example, the {MERGEFIELD Weather.condition *Upper} field denotes the MERGEFIELD field bound to the Weather.condition data field, which displays the text in all caps.

Definition

Programmatically, a field is implemented as the Field client object. A list of field objects in the active sub-document can be accessed through the fieldsInfo client property (SubDocument.fieldsInfo) in the following notation:

clientRichEditName.document.activeSubDocument.fieldsInfo

A document field can be defined using the following characteristics.

Client API

The following client commands are available for manipulating fields in a document. Call the commands in the notation given below:

clientRichEditName.commands.commandName.execute(parameter_if_any)

Command NameLinkDescription
createDateFieldRichEditCommands.createDateFieldGets a command to insert and update a field with a DATE code.
createFieldRichEditCommands.createFieldGets a command to add a field at the current position in a document.
createMergeFieldRichEditCommands.createMergeFieldGets a command to replace the selection with a MERGEFIELD (a data source column name is passed with a parameter).
createPageCountFieldRichEditCommands.createPageCountFieldGets a command to replace the selection with a NUMPAGES field displaying the total number of pages.
createPageFieldRichEditCommands.createPageFieldGets a command to replace the selection with a PAGE field displaying the current page number.
createTimeFieldRichEditCommands.createTimeFieldGets a command to replace the selection with a TIME field displaying the current time.
mergeFieldDialogRichEditCommands.mergeFieldDialogGets a command to invoke the Insert Merge Field dialog window.
showAllFieldCodesRichEditCommands.showAllFieldCodesGets a command to display all field codes in place of the fields in the document.
showFieldCodesRichEditCommands.showFieldCodesGets a command to display the selected field’s codes.
updateAllFieldsRichEditCommands.updateAllFieldsGets a command to update all fields in the document.
updateFieldRichEditCommands.updateFieldGets a command to update each field’s result in the selection.

See Also

Demo: Fields

Demo: Document Variables

Fields

Field Codes

Mail Merge