[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
   [Collapse]RichEditControl Document
    [Expand]Document Structure
    [Collapse]Document Elements
      Positions and Ranges
      Inline Pictures
      Hyperlinks and Bookmarks
      Headers and Footers
      Range Permissions
      Numbered and Bulleted Lists
      Text Boxes
      Document Properties
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Spell Checking
    Mail Merge
    Restrictions and Protection
    Syntax Highlighting
   [Expand]Visual Elements
    Keyboard Shortcuts
    HTML Tag Support
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap 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]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Positions and Ranges

Position and range are cornerstone Rich Edit entities that define the location of every object within a logical document structure.

Position is a zero-based index of every character within a text string. It is represented by the DocumentPosition class. The best visual presentation of the position is a text cursor (caret). Placed in the beginning of the document, it is located before the first character. This is a 0 position. When the cursor is moved forward to the next character, it moves to the position 1, and so on.

The range in turn is a distance between two positions, represented by the DocumentRange.Start and DocumentRange.End properties. The difference between the ending and starting position defines the DocumentRange.Length.

To create a DocumentRange, use the SubDocument.CreateRange method. To obtain a range of the selected document fragment, use the Document.Selection property.

The text can be added to the range by the SubDocument.AppendText, SubDocument.InsertText or SubDocument.InsertSingleLineText methods. Adding new text elements increases the DocumentRange.End and DocumentRange.Length property values.

To delete the characters from the range, use the SubDocument.Delete method. After deletion, the DocumentRange.End and DocumentRange.Length property values will lessen.

If the text preceding the range is removed, the DocumentRange.Length value remains the same, whereas the start and end range positions move backward, hence the DocumentRange.Start and DocumentRange.End values decrease.

Each document entity has the Range property, so you can get the range occupied by the specific unit. And vice versa, you can retrieve the document entity from the specified range. The following table shows what method should be used to retrieve any document entity.

Object Method













Shape (floating image or text box)













If you operate with a selection range, any of the above-listed methods should be enclosed within DocumentRange.BeginUpdateDocument - DocumentRange.EndUpdateDocument methods pair. Otherwise, an incorrect document model might be selected, resulting in an exception "Error: specified document position or range belongs to other document or subdocument" being thrown.

Since there is no exact correspondence between the logical and physical document structures, it is hard to determine a line or a page where a certain range or position is located. But there are a few methods that can help you obtain an approximate location of the required position.

Expanded See Also

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