[Expand]General Information
[Collapse]WinForms Controls
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Map Control
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
    Supported Formats
   [Expand]Getting Started
   [Expand]RichEditControl Document
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Spell Checking
    AutoCorrect Feature
    Mail Merge
    Restrictions and Protection
    Syntax Highlighting
   [Expand]Visual Elements
    Keyboard Shortcuts
    HTML Tag Support
    [Expand]Text Boxes
    [Expand]Document Elements
      How to: Create a Table of Contents
      How to: Create a Table of Contents in Code
      How to: Add and Modify Fields
      How to: Handle the HyperlinkClick Event to Invoke the Custom Form
      How to: Retrieve the List of Document Fonts using the Visitor-Iterator Pattern
    [Expand]Search and Replace
    [Expand]Spell Check
    [Expand]Import and Export
    [Expand]UI Customization
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[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]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Add and Modify Fields

The following example illustrates how to add and modify fields manually.

All the fields in the document are contained in the FieldCollection, accessible through the SubDocument.Fields property.

Expanded Insert a Field

To create a field, use the FieldCollection.Create property, as illustrated below.

This code snippet inserts the DATE field at the caret position.

To create a field from the selected range, use the FieldCollection.Create property with the passed range.

This code snippet creates a field from the selected range so that the selected text becomes the field code.

Expanded Modify Field Code

To modify field content, use the SubDocument.BeginUpdate - SubDocument.EndUpdate paired methods.

To insert a field format switch, use the SubDocument.InsertText method. Use the end position of the field code range as a method argument.

Use the Field.Update method to update the field result.


The header and footer as well as the text box in the RichEditControl document do not belong to the main document body. Use the Section.BeginUpdateHeader - Section.EndUpdateHeader or Section.BeginUpdateFooter - Section.EndUpdateFooter paired methods to obtain the header or footer. Refer to the How to: Create and Modify Header topic for details. The TextBox.Document property allows you to retrieve the text box content and update the corresponding fields.

Expanded See Also

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