[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Collapse]Office File API
  Demo Application
  Redistribution and Deployment
 [Expand]Spreadsheet Document API
 [Expand]Word Processing Document API
 [Expand]PDF Document API
 [Expand]Excel Export Library
 [Expand]Snap Report API
 [Expand]Zip Compression and Archive API
 [Expand]Barcode Generation API
 [Expand]Unit Conversion API
 [Collapse]API Reference
  [Expand]DevExpress.BarCodes
  [Expand]DevExpress.Compression
  [Expand]DevExpress.Docs.Text
  [Expand]DevExpress.Office
  [Expand]DevExpress.Office.Drawing
  [Expand]DevExpress.Office.Export
  [Expand]DevExpress.Office.Export.Html
  [Expand]DevExpress.Office.Import
  [Expand]DevExpress.Office.Localization
  [Expand]DevExpress.Office.Options
  [Expand]DevExpress.Office.Services
  [Expand]DevExpress.Office.Utils
  [Expand]DevExpress.Pdf
  [Expand]DevExpress.Pdf.Localization
  [Expand]DevExpress.Snap
  [Expand]DevExpress.Spreadsheet
  [Expand]DevExpress.Spreadsheet.Charts
  [Expand]DevExpress.Spreadsheet.Drawings
  [Expand]DevExpress.Spreadsheet.Export
  [Expand]DevExpress.Spreadsheet.Formulas
  [Expand]DevExpress.Spreadsheet.Functions
  [Expand]DevExpress.UnitConversion
  [Expand]DevExpress.XtraPrinting
  [Expand]DevExpress.XtraPrintingLinks
  [Collapse]DevExpress.XtraRichEdit
   [Expand]Argument Class
   [Expand]ArgumentCollection Class
   [Expand]AuthenticationOptions Class
   [Expand]AutoCorrectEventArgs Class
    AutoCorrectEventHandler Delegate
   [Expand]AutoCorrectInfo Class
   [Expand]AutoCorrectOptions Class
   [Expand]AutoCorrectReplaceInfo Class
   [Expand]AutoCorrectReplaceInfoCollection Class
    AutoSizeMode Enumeration
   [Expand]BeforeExportEventArgs Class
    BeforeExportEventHandler Delegate
   [Expand]BeforeImportEventArgs Class
    BeforeImportEventHandler Delegate
   [Expand]BeforePagePaintEventArgs Class
    BeforePagePaintEventHandler Delegate
   [Expand]BookmarkFormShowingEventArgs Class
    BookmarkFormShowingEventHandler Delegate
   [Expand]BookmarkOptions Class
   [Expand]CalculateDocumentVariableEventArgs Class
    CalculateDocumentVariableEventHandler Delegate
    CalculationModeType Enumeration
   [Expand]ColumnsSetupFormShowingEventArgs Class
    ColumnsSetupFormShowingEventHandler Delegate
   [Expand]CommentEditingEventArgs Class
    CommentEditingEventHandler Delegate
   [Expand]CommentOptions Class
    ConflictNameAction Enumeration
   [Expand]CopyPasteOptions Class
   [Expand]CustomizeMergeFieldsEventArgs Class
    CustomizeMergeFieldsEventHandler Delegate
   [Expand]DataFormatOptions Class
   [Expand]DecryptionFailedEventArgs Class
    DecryptionFailedEventHandler Delegate
   [Expand]DeleteTableCellsFormShowingEventArgs Class
    DeleteTableCellsFormShowingEventHandler Delegate
   [Expand]DocumentCapabilitiesOptions Class
    DocumentCapability Enumeration
   [Expand]DocumentExportCapabilities Structure
   [Expand]DocumentFormat Structure
    DocumentLayoutUnit Enumeration
   [Expand]DocumentPropertiesFormShowingEventArgs Class
    DocumentPropertiesFormShowingEventHandler Delegate
   [Expand]DocumentProtectionQueryNewPasswordFormShowingEventArgs Class
    DocumentProtectionQueryNewPasswordFormShowingEventHandler Delegate
   [Expand]DocumentProtectionQueryPasswordFormShowingEventArgs Class
    DocumentProtectionQueryPasswordFormShowingEventHandler Delegate
   [Expand]DocumentSaveOptions Class
   [Expand]DocumentSearchOptions Class
   [Expand]DocumentVariableCollection Class
   [Expand]DocVariableValue Class
   [Expand]DraftView Class
   [Expand]DraftViewLayoutOptions Class
    DragDropMode Enumeration
   [Expand]EditStyleFormShowingEventArgs Class
    EditStyleFormShowingEventHandler Delegate
   [Expand]EncryptDocumentFormShowingEventArgs Class
    EncryptDocumentFormShowingEventHandler Delegate
   [Expand]EncryptedFileIntegrityCheckFailedEventArgs Class
    EncryptedFileIntegrityCheckFailedEventHandler Delegate
   [Expand]EncryptedFilePasswordCheckFailedEventArgs Class
    EncryptedFilePasswordCheckFailedEventHandler Delegate
   [Expand]EncryptedFilePasswordRequestedEventArgs Class
    EncryptedFilePasswordRequestedEventHandler Delegate
   [Expand]FieldOptions Class
    FieldsHighlightMode Enumeration
   [Expand]FloatingInlineObjectLayoutOptionsFormShowingEventArgs Class
    FloatingInlineObjectLayoutOptionsFormShowingEventHandler Delegate
   [Expand]FontFormShowingEventArgs Class
    FontFormShowingEventHandler Delegate
   [Expand]FormattingMarkVisibilityOptions Class
   [Expand]FormShowingEventArgs Class
   [Expand]HeaderFooterEditingEventArgs Class
    HeaderFooterEditingEventHandler Delegate
   [Expand]HitTestManager Class
    HitTestSearchOption Enumeration
   [Expand]HorizontalRulerOptions Class
    HtmlImageSourceType Enumeration
   [Expand]HyperlinkClickEventArgs Class
    HyperlinkClickEventHandler Delegate
   [Expand]HyperlinkFormShowingEventArgs Class
    HyperlinkFormShowingEventHandler Delegate
   [Expand]HyperlinkOptions Class
   [Expand]IDataSourceContainerOptions Interface
   [Expand]InsertMergeFieldFormShowingEventArgs Class
    InsertMergeFieldFormShowingEventHandler Delegate
   [Expand]InsertTableCellsFormShowingEventArgs Class
    InsertTableCellsFormShowingEventHandler Delegate
   [Expand]InsertTableFormShowingEventArgs Class
    InsertTableFormShowingEventHandler Delegate
   [Expand]IRichEditControl Interface
   [Expand]IRichEditDocumentServer Interface
   [Expand]IRichEditViewVisitor Interface
    LineBreakSubstitute Enumeration
   [Expand]LineNumberingFormShowingEventArgs Class
    LineNumberingFormShowingEventHandler Delegate
   [Expand]MailMergeCustomSeparators Class
   [Expand]MailMergeFinishedEventArgs Class
    MailMergeFinishedEventHandler Delegate
   [Expand]MailMergeRecordFinishedEventArgs Class
    MailMergeRecordFinishedEventHandler Delegate
   [Expand]MailMergeRecordStartedEventArgs Class
    MailMergeRecordStartedEventHandler Delegate
   [Expand]MailMergeStartedEventArgs Class
    MailMergeStartedEventHandler Delegate
   [Expand]NumberingListFormShowingEventArgs Class
    NumberingListFormShowingEventHandler Delegate
   [Expand]NumberingOptions Class
    PageBreakInsertMode Enumeration
   [Expand]PageLayoutInfo Structure
   [Expand]PageLayoutPosition Class
   [Expand]PageSetupFormShowingEventArgs Class
    PageSetupFormShowingEventHandler Delegate
   [Expand]ParagraphFormShowingEventArgs Class
    ParagraphFormShowingEventHandler Delegate
    PasteMode Enumeration
   [Expand]PasteSpecialFormShowingEventArgs Class
    PasteSpecialFormShowingEventHandler Delegate
    PdfBookmarkDisplayMode Enumeration
   [Expand]PrintingOptions Class
   [Expand]PrintLayoutView Class
   [Expand]PrintLayoutViewLayoutOptions Class
    PrintPreviewFormKind Enumeration
   [Expand]RangeEditingPermissionsFormShowingEventArgs Class
    RangeEditingPermissionsFormShowingEventHandler Delegate
   [Expand]RangePermissionOptions Class
    RichEditBaseValueSource Enumeration
   [Expand]RichEditBehaviorOptions Class
    RichEditBookmarkVisibility Enumeration
   [Expand]RichEditBrushBase Class
   [Expand]RichEditClipboardSetDataExceptionEventArgs Class
    RichEditClipboardSetDataExceptionEventHandler Delegate
    RichEditCommentVisibility Enumeration
   [Expand]RichEditControlCompatibility Class
   [Expand]RichEditControlOptionsBase Class
    RichEditDashStyle Enumeration
    RichEditDecryptionError Enumeration
   [Expand]RichEditDecryptionException Class
   [Collapse]RichEditDocumentServer Class
     RichEditDocumentServer Members
     RichEditDocumentServer Constructor
    [Expand]RichEditDocumentServer Properties
    [Collapse]RichEditDocumentServer Events
      AfterExport Event
      BeforeExport Event
      BeforeImport Event
      BeforePagePaint Event
      CalculateDocumentVariable Event
      CommentInserted Event
      ContentChanged Event
      CustomPropertiesChanged Event
      DecryptionFailed Event
      DocBytesChanged Event
      DocumentClosing Event
      DocumentEncryptionChanged Event
      DocumentLoaded Event
      DocumentPropertiesChanged Event
      EmptyDocumentCreated Event
      EncryptedFileIntegrityCheckFailed Event
      EncryptedFilePasswordCheckFailed Event
      EncryptedFilePasswordRequested Event
      HtmlTextChanged Event
      InitializeDocument Event
      InvalidFormatException Event
      MailMergeFinished Event
      MailMergeRecordFinished Event
      MailMergeRecordStarted Event
      MailMergeStarted Event
      MhtTextChanged Event
      ModifiedChanged Event
      OpenDocumentBytesChanged Event
      OpenXmlBytesChanged Event
      RtfTextChanged Event
      SelectionChanged Event
      UnhandledException Event
      WordMLTextChanged Event
    [Expand]RichEditDocumentServer Methods
    RichEditFormattingMarkVisibility Enumeration
   [Expand]RichEditHitTestResult Class
   [Expand]RichEditInvalidFormatExceptionEventArgs Class
    RichEditInvalidFormatExceptionEventHandler Delegate
   [Expand]RichEditLayoutOptions Class
   [Expand]RichEditMailMergeOptions Class
   [Expand]RichEditNotificationOptions Class
   [Expand]RichEditPenBase Class
    RichEditRangePermissionVisibility Enumeration
    RichEditRulerVisibility Enumeration
    RichEditTableGridLinesVisibility Enumeration
   [Expand]RichEditUnhandledExceptionEventArgs Class
    RichEditUnhandledExceptionEventHandler Delegate
   [Expand]RichEditView Class
   [Expand]RichEditViewRepository Class
    RichEditViewType Enumeration
   [Expand]RulerOptions Class
   [Expand]SearchFormShowingEventArgs Class
    SearchFormShowingEventHandler Delegate
   [Expand]ShowFormEventArgs Class
   [Expand]SimpleView Class
   [Expand]SimpleViewLayoutOptions Class
   [Expand]SpellCheckerOptions Class
   [Expand]SpellingErrorLimitExceededEventArgs Class
    SpellingErrorLimitExceededEventHandler Delegate
   [Expand]SplitTableCellsFormShowingEventArgs Class
    SplitTableCellsFormShowingEventHandler Delegate
   [Expand]SymbolFormShowingEventArgs Class
    SymbolFormShowingEventHandler Delegate
   [Expand]TableOptions Class
   [Expand]TableOptionsFormShowingEventArgs Class
    TableOptionsFormShowingEventHandler Delegate
   [Expand]TablePropertiesFormShowingEventArgs Class
    TablePropertiesFormShowingEventHandler Delegate
   [Expand]TableStyleFormShowingEventArgs Class
    TableStyleFormShowingEventHandler Delegate
   [Expand]TabsFormShowingEventArgs Class
    TabsFormShowingEventHandler Delegate
    UpdateDocVariablesBeforePrint Enumeration
    UpdateLockedFields Enumeration
   [Expand]VerticalRulerOptions Class
  [Expand]DevExpress.XtraRichEdit.API.Layout
  [Expand]DevExpress.XtraRichEdit.API.Native
  [Expand]DevExpress.XtraRichEdit.API.Native.Implementation
  [Expand]DevExpress.XtraRichEdit.Commands
  [Expand]DevExpress.XtraRichEdit.Export
  [Expand]DevExpress.XtraRichEdit.Export.Html
  [Expand]DevExpress.XtraRichEdit.Export.PlainText
  [Expand]DevExpress.XtraRichEdit.Export.Rtf
  [Expand]DevExpress.XtraRichEdit.Forms
  [Expand]DevExpress.XtraRichEdit.Import
  [Expand]DevExpress.XtraRichEdit.Localization
  [Expand]DevExpress.XtraRichEdit.Services
  [Expand]DevExpress.XtraRichEdit.Utils
  [Expand]DevExpress.XtraSpreadsheet
  [Expand]DevExpress.XtraSpreadsheet.Export
  [Expand]DevExpress.XtraSpreadsheet.Export.Html
  [Expand]DevExpress.XtraSpreadsheet.Import
  [Expand]DevExpress.XtraSpreadsheet.Localization
  [Expand]DevExpress.XtraSpreadsheet.Services
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

RichEditDocumentServer.CalculateDocumentVariable Event

Fires when the DOCVARIABLE field is updated.

Namespace:DevExpress.XtraRichEdit
Assembly:DevExpress.RichEdit.v19.1.Core.dll

Expanded Syntax

Expanded Event Data

The event handler receives an argument of type CalculateDocumentVariableEventArgs containing data related to this event.

The following CalculateDocumentVariableEventArgs properties provide information specific to this event.
Property Description
Arguments Provides access to a collection of arguments within the DOCVARIABLE field.
FieldLocked Gets or sets a locked attribute to the field for which the event occurs.
Handled Gets or sets whether the default action is required.
KeepLastParagraph Gets or sets whether the last paragraph of the inserted document is kept in the resulting document.
PreserveInsertedContentFormatting Gets or sets whether to insert an additional hidden paragraph so that the inserted content is not formatted with the DOCVARIABLE field's paragraph formatting.
Value Gets or sets the value of the DOCVARIABLE field that fired the event.
VariableName Gets the name of the document variable to which the DOCVARIABLE field refers.

Expanded Remarks

The CalculateDocumentVariable event is fired when the DOCVARIABLE field value is calculated.

The event is fired when a field is updated (using Field.Update or FieldCollection.Update methods), or during the Mail Merge on the MailMerge method call. Handle this event to analyze DOCVARIABLE field switches and arguments, and provide custom content to insert into this field.

Assign a special DocVariableValue.Current value to the CalculateDocumentVariableEventArgs.Value property and set e.Handled to true to retain the existing DOCVARIABLE value.

You can specify the FieldOptions.UpdateLockedFields property to raise the event for locked DOCVARIABLE fields.

You can lock/unlock the field within the CalculateDocumentVariable handler using the CalculateDocumentVariableEventArgs.FieldLocked property. Set e.Handled to true to apply changes.

If you use a nested field in your project, such as {DOCVARIABLE {MERGEFIELD MyDataField_1}}, check the fields' CalculateDocumentVariableEventArgs.Arguments value. When the CalculateDocumentVariable event is fired for the first time, e.Arguments contains the <<MyDataField_1>> (the placeholder for the field) since the merge field is not yet calculated. Do not handle the event if the argument is invalid (use comparison and return statements if required) .

Note

If you use MailMerge method to evaluate nested DOCVARIABLE fields, set the RichEditMailMergeOptions.ViewMergedData option to true. Otherwise you will get field placeholders instead of values within the CalculateDocumentVariable handler.

Expanded Example

Note

A complete code sample project is available at How to use document variable (DOCVARIABLE) fields.

This code snippet demonstrates how to handle the Document.CalculateDocumentVariable event to insert dynamic content into the document. In this example, it is used to get weather conditions. A variable name specified in the DOCVARIABLE indicates a choice between location and weather, while the location itself is specified by the field argument.

Expanded See Also

Is this topic helpful?​​​​​​​