Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Expand]Controls and Libraries
 [Expand]Common Features
  Get More Help
 [Collapse]API Reference
  [Expand]DevExpress.DataAccess.UI.Design
  [Expand]DevExpress.DataAccess.UI.EntityFramework
  [Expand]DevExpress.DataAccess.UI.Excel
  [Expand]DevExpress.DataAccess.UI.Localization
  [Expand]DevExpress.DataAccess.UI.ObjectBinding
  [Expand]DevExpress.DataAccess.UI.Sql
  [Expand]DevExpress.DataAccess.UI.Wizard
  [Expand]DevExpress.DataAccess.UI.Wizard.Services
  [Expand]DevExpress.DataAccess.UI.Wizard.Views
  [Expand]DevExpress.DocumentView
  [Expand]DevExpress.DocumentView.Controls
  [Expand]DevExpress.LookAndFeel
  [Expand]DevExpress.LookAndFeel.Helpers
  [Expand]DevExpress.Skins
  [Expand]DevExpress.Snap
  [Expand]DevExpress.Snap.API.Native
  [Expand]DevExpress.Snap.Core
  [Expand]DevExpress.Snap.Core.API
  [Expand]DevExpress.Snap.Core.Fields
  [Expand]DevExpress.Snap.Core.Forms
  [Expand]DevExpress.Snap.Core.Options
  [Expand]DevExpress.Snap.Core.Services
  [Expand]DevExpress.Snap.Extensions
  [Expand]DevExpress.Snap.Extensions.Localization
  [Expand]DevExpress.Snap.Extensions.UI
  [Expand]DevExpress.Snap.Localization
  [Expand]DevExpress.Snap.Options
  [Expand]DevExpress.Snap.Services
  [Expand]DevExpress.Utils
  [Expand]DevExpress.Utils.Animation
  [Expand]DevExpress.Utils.Controls
  [Expand]DevExpress.Utils.Drawing
  [Expand]DevExpress.Utils.Menu
  [Expand]DevExpress.Utils.Taskbar
  [Expand]DevExpress.Utils.Taskbar.Core
  [Expand]DevExpress.Utils.UI.Localization
  [Expand]DevExpress.Utils.VisualEffects
  [Expand]DevExpress.Utils.Win
  [Expand]DevExpress.XtraBars
  [Expand]DevExpress.XtraBars.Alerter
  [Expand]DevExpress.XtraBars.Docking
  [Expand]DevExpress.XtraBars.Docking2010
  [Expand]DevExpress.XtraBars.Docking2010.Customization
  [Expand]DevExpress.XtraBars.Docking2010.Views
  [Expand]DevExpress.XtraBars.Docking2010.Views.NativeMdi
  [Expand]DevExpress.XtraBars.Docking2010.Views.Tabbed
  [Expand]DevExpress.XtraBars.Docking2010.Views.Widget
  [Expand]DevExpress.XtraBars.Docking2010.Views.WindowsUI
  [Expand]DevExpress.XtraBars.Localization
  [Expand]DevExpress.XtraBars.Navigation
  [Expand]DevExpress.XtraBars.Ribbon
  [Expand]DevExpress.XtraBars.Ribbon.Gallery
  [Expand]DevExpress.XtraBars.Ribbon.ViewInfo
  [Expand]DevExpress.XtraBars.ToastNotifications
  [Expand]DevExpress.XtraBars.Utils
  [Expand]DevExpress.XtraBars.WinRTLiveTiles
  [Expand]DevExpress.XtraCharts
  [Expand]DevExpress.XtraCharts.Designer
  [Expand]DevExpress.XtraCharts.Wizard
  [Expand]DevExpress.XtraDataLayout
  [Expand]DevExpress.XtraDiagram
  [Expand]DevExpress.XtraDiagram.Options
  [Expand]DevExpress.XtraEditors
  [Expand]DevExpress.XtraEditors.ButtonPanel
  [Expand]DevExpress.XtraEditors.Calendar
  [Expand]DevExpress.XtraEditors.Camera
  [Expand]DevExpress.XtraEditors.Container
  [Expand]DevExpress.XtraEditors.Controls
  [Expand]DevExpress.XtraEditors.CustomEditor
  [Expand]DevExpress.XtraEditors.DXErrorProvider
  [Expand]DevExpress.XtraEditors.Filtering
  [Expand]DevExpress.XtraEditors.Mask
  [Expand]DevExpress.XtraEditors.Persistent
  [Expand]DevExpress.XtraEditors.Repository
  [Expand]DevExpress.XtraEditors.ViewInfo
  [Expand]DevExpress.XtraFilterEditor
  [Expand]DevExpress.XtraGauges.Presets.Styles
  [Expand]DevExpress.XtraGauges.Win
  [Expand]DevExpress.XtraGauges.Win.Base
  [Expand]DevExpress.XtraGauges.Win.Gauges.Circular
  [Expand]DevExpress.XtraGauges.Win.Gauges.Digital
  [Expand]DevExpress.XtraGauges.Win.Gauges.Linear
  [Expand]DevExpress.XtraGauges.Win.Gauges.State
  [Expand]DevExpress.XtraGrid
  [Expand]DevExpress.XtraGrid.Columns
  [Expand]DevExpress.XtraGrid.EditForm
  [Expand]DevExpress.XtraGrid.FilterEditor
  [Expand]DevExpress.XtraGrid.Localization
  [Expand]DevExpress.XtraGrid.Views.BandedGrid
  [Expand]DevExpress.XtraGrid.Views.BandedGrid.ViewInfo
  [Expand]DevExpress.XtraGrid.Views.Base
  [Expand]DevExpress.XtraGrid.Views.Base.ViewInfo
  [Expand]DevExpress.XtraGrid.Views.Card
  [Expand]DevExpress.XtraGrid.Views.Card.ViewInfo
  [Expand]DevExpress.XtraGrid.Views.Grid
  [Expand]DevExpress.XtraGrid.Views.Grid.ViewInfo
  [Expand]DevExpress.XtraGrid.Views.Layout
  [Expand]DevExpress.XtraGrid.Views.Layout.Events
  [Expand]DevExpress.XtraGrid.Views.Layout.ViewInfo
  [Expand]DevExpress.XtraGrid.Views.Printing
  [Expand]DevExpress.XtraGrid.Views.Tile
  [Expand]DevExpress.XtraGrid.Views.WinExplorer
  [Expand]DevExpress.XtraGrid.WinExplorer
  [Expand]DevExpress.XtraLayout
  [Expand]DevExpress.XtraLayout.Customization
  [Expand]DevExpress.XtraLayout.HitInfo
  [Expand]DevExpress.XtraLayout.Localization
  [Expand]DevExpress.XtraLayout.Utils
  [Expand]DevExpress.XtraMap
  [Expand]DevExpress.XtraMap.Printing
  [Expand]DevExpress.XtraNavBar
  [Expand]DevExpress.XtraNavBar.ViewInfo
  [Expand]DevExpress.XtraPdfViewer
  [Expand]DevExpress.XtraPdfViewer.Commands
  [Expand]DevExpress.XtraPdfViewer.Localization
  [Expand]DevExpress.XtraPivotGrid
  [Expand]DevExpress.XtraPivotGrid.Data
  [Expand]DevExpress.XtraPrinting
  [Expand]DevExpress.XtraPrinting.Control
  [Expand]DevExpress.XtraPrinting.Preview
  [Expand]DevExpress.XtraPrintingLinks
  [Expand]DevExpress.XtraReports.UI
  [Collapse]DevExpress.XtraRichEdit
   [Expand]HorizontalScrollbarOptions Class
    ImeCloseStatus Enumeration
   [Expand]PopupMenuShowingEventArgs Class
    PopupMenuShowingEventHandler Delegate
   [Expand]PreparePopupMenuEventArgs Class
    PreparePopupMenuEventHandler Delegate
   [Expand]RichEditAppearance Class
   [Expand]RichEditBrush Class
   [Collapse]RichEditControl Class
     RichEditControl Members
     RichEditControl Constructor
    [Expand]RichEditControl Properties
    [Collapse]RichEditControl Events
      ActiveRecordChanged Event
      ActiveRecordChanging Event
      ActiveViewChanged Event
      AfterExport Event
      AutoCorrect Event
      BeforeDispose Event
      BeforeExport Event
      BeforeImport Event
      BeforePagePaint Event
      BookmarkFormShowing Event
      BorderShadingFormShowing Event
      CalculateDocumentVariable Event
      ClipboardSetDataException Event
      CloseReviewingPane Event
      ColumnsSetupFormShowing Event
      CommentInserted Event
      ContentChanged Event
      CustomDrawActiveView Event
      CustomizeMergeFields Event
      CustomMarkDraw Event
      CustomPropertiesChanged Event
      DeleteTableCellsFormShowing Event
      DocumentClosing Event
      DocumentLoaded Event
      DocumentPropertiesChanged Event
      DocumentPropertiesFormShowing Event
      DocumentProtectionChanged Event
      DocumentProtectionQueryNewPasswordFormShowing Event
      DocumentProtectionQueryPasswordFormShowing Event
      EditStyleFormShowing Event
      EmptyDocumentCreated Event
      FinishHeaderFooterEditing Event
      FloatingInlineObjectLayoutOptionsFormShowing Event
      FontFormShowing Event
      HtmlTextChanged Event
      HyperlinkClick Event
      HyperlinkFormShowing Event
      InitializeDocument Event
      InsertMergeFieldFormShowing Event
      InsertTableCellsFormShowing Event
      InsertTableFormShowing Event
      InvalidFormatException Event
      LineNumberingFormShowing Event
      MailMergeFinished Event
      MailMergeRecordFinished Event
      MailMergeRecordStarted Event
      MailMergeStarted Event
      MhtTextChanged Event
      ModifiedChanged Event
      NumberingListFormShowing Event
      OpenDocumentBytesChanged Event
      OpenXmlBytesChanged Event
      OvertypeChanged Event
      PageSetupFormShowing Event
      ParagraphFormShowing Event
      PasteSpecialFormShowing Event
      PopupMenuShowing Event
      PreparePopupMenu Event
      PropertyChanged Event
      RangeEditingPermissionsFormShowing Event
      ReadOnlyChanged Event
      RtfTextChanged Event
      SearchFormShowing Event
      SelectionChanged Event
      SpellingErrorLimitExceeded Event
      SplitTableCellsFormShowing Event
      StartHeaderFooterEditing Event
      SymbolFormShowing Event
      TableOptionsFormShowing Event
      TablePropertiesFormShowing Event
      TableStyleFormShowing Event
      TabsFormShowing Event
      UnhandledException Event
      UnitChanged Event
      UnitChanging Event
      UpdateUI Event
      VisiblePagesChanged Event
      WordMLTextChanged Event
      ZoomChanged Event
    [Expand]RichEditControl Methods
   [Expand]RichEditControlOptions Class
   [Expand]RichEditCustomMarkDrawEventArgs Class
    RichEditCustomMarkDrawEventHandler Delegate
    RichEditMenuType Enumeration
   [Expand]RichEditPen Class
    RichEditScrollbarVisibility Enumeration
   [Expand]RichEditViewCustomDrawEventArgs Class
    RichEditViewCustomDrawEventHandler Delegate
   [Expand]ScrollbarOptions Class
   [Expand]VerticalScrollbarOptions Class
  [Expand]DevExpress.XtraRichEdit.Commands
  [Expand]DevExpress.XtraRichEdit.Export
  [Expand]DevExpress.XtraRichEdit.Import
  [Expand]DevExpress.XtraRichEdit.Localization
  [Expand]DevExpress.XtraRichEdit.Menu
  [Expand]DevExpress.XtraScheduler
  [Expand]DevExpress.XtraScheduler.Drawing
  [Expand]DevExpress.XtraScheduler.Printing
  [Expand]DevExpress.XtraScheduler.Reporting
  [Expand]DevExpress.XtraScheduler.Reporting.UI
  [Expand]DevExpress.XtraScheduler.Services
  [Expand]DevExpress.XtraScheduler.Services.Implementation
  [Expand]DevExpress.XtraScheduler.UI
  [Expand]DevExpress.XtraSpellChecker
  [Expand]DevExpress.XtraSpellChecker.Localization
  [Expand]DevExpress.XtraSplashForm
  [Expand]DevExpress.XtraSplashScreen
  [Expand]DevExpress.XtraSpreadsheet
  [Expand]DevExpress.XtraSpreadsheet.Services
  [Expand]DevExpress.XtraTab
  [Expand]DevExpress.XtraTab.Buttons
  [Expand]DevExpress.XtraTab.ViewInfo
  [Expand]DevExpress.XtraTabbedMdi
  [Expand]DevExpress.XtraToolbox
  [Expand]DevExpress.XtraTreeList
  [Expand]DevExpress.XtraTreeList.Columns
  [Expand]DevExpress.XtraTreeList.Data
  [Expand]DevExpress.XtraTreeList.Localization
  [Expand]DevExpress.XtraTreeList.Menu
  [Expand]DevExpress.XtraTreeList.Nodes
  [Expand]DevExpress.XtraTreeList.Nodes.Operations
  [Expand]DevExpress.XtraTreeList.StyleFormatConditions
  [Expand]DevExpress.XtraTreeMap
  [Expand]DevExpress.XtraVerticalGrid
  [Expand]DevExpress.XtraVerticalGrid.Events
  [Expand]DevExpress.XtraVerticalGrid.Localization
  [Expand]DevExpress.XtraVerticalGrid.Rows
  [Expand]DevExpress.XtraWaitForm
  [Expand]DevExpress.XtraWizard
[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
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

RichEditControl.CalculateDocumentVariable Event

Fires for the DOCVARIABLE field and allows you to update its value.

Namespace:DevExpress.XtraRichEdit
Assembly:DevExpress.XtraRichEdit.v17.2.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 occurs for the DOCVARIABLE field. The event is fired when a field is updated (using UI commands, DevExpress.XtraRichEdit.API.Native.Field.Update or DevExpress.XtraRichEdit.API.Native.FieldCollection.Update methods), or during Mail Merge when the MailMerge method is called.

When a DOCVARIABLE field is locked (the DevExpress.XtraRichEdit.API.Native.Field.Locked property is true), the CalculateDocumentVariable is normally not raised for the field. However, you can specify the RichEditControl's option DevExpress.XtraRichEdit.FieldOptions.UpdateLockedFields to raise the event for locked DOCVARIABLE fields.

You can handle this event to analyze DOCVARIABLE field switches and arguments, and provide custom content to insert into this field. The content can be of any supported type, and even as complex as another mail merged document. See our Master-Detail demo module, for an example.

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

Tip

Previous field value is reset when this event is raised. If you wish to retain the existing value, assign a special DevExpress.XtraRichEdit.DocVariableValue.Current value to the DevExpress.XtraRichEdit.CalculateDocumentVariableEventArgs.Value property and set e.Handled to true .

Note

If you use nested fields in your project, such as {DOCVARIABLE {MERGEFIELD MyDataField_1}}, always provide a check for the e.Arguments[0] value. When the CalculateDocumentVariable event is fired for the first time, e.Arguments[0] 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 supplied is not what you are expecting (use comparison and return statements if required) .

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E3099.

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

Expanded See Also

How would you rate this topic?​​​​​​​