Back to Devexpress

DocumentRange.BeginUpdateDocument() Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentrange-c845f643.md

latest8.6 KB
Original Source

DocumentRange.BeginUpdateDocument() Method

Starts modifying the document obtained via the document’s range (e.g. via selection).

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
SubDocument BeginUpdateDocument()
vb
Function BeginUpdateDocument As SubDocument

Returns

TypeDescription
SubDocument

A SubDocument instance allowing you to safely modify the document.

|

Remarks

Use the DocumentRange.BeginUpdateDocument - DocumentRange.EndUpdateDocument pair to modify the document obtained via selection (i.e. by using the Document.Selection property). In that case, it is very important to distinguish different parts of the document, such as header, footer or body. The BeginUpdateDocument method implements this requirement.

Example

This code sample demonstrates how to use and modify the selected part of the document. The selection can be located in the main part of the document, within the table, in the header, footer or in a text box. The DocumentRange.BeginUpdateDocument method is a versatile method for accessing any document range, irrespective of its location. You are advised to obtain the selection using the Document.Selection property and use the SubDocument methods within the DocumentRange.BeginUpdateDocument - DocumentRange.EndUpdateDocument method pair.

csharp
DocumentRange range = richEditControl1.Document.Selection;
SubDocument doc = range.BeginUpdateDocument();
string plainText = doc.GetText(range);
MessageBox.Show(plainText, "Selected Text");
doc.InsertText(range.Start,"->");
doc.InsertText(range.End, "<-");
range.EndUpdateDocument(doc);
vb
Dim range As DocumentRange = richEditControl1.Document.Selection
Dim doc As SubDocument = range.BeginUpdateDocument()
Dim plainText As String = doc.GetText(range)
MessageBox.Show(plainText, "Selected Text")
doc.InsertText(range.Start,"->")
doc.InsertText(range.End, "<-")
range.EndUpdateDocument(doc)

The following code snippets (auto-collected from DevExpress Examples) contain references to the BeginUpdateDocument() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-richedit-save-text-from-a-range-in-different-formats/CS/GetTextMethodsExample/Form1.cs#L32

csharp
DevExpress.XtraRichEdit.API.Native.DocumentRange selection = richEditControl.Document.Selection;
DevExpress.XtraRichEdit.API.Native.SubDocument doc = selection.BeginUpdateDocument();
mhtText = doc.GetMhtText(selection);

winforms-rich-edit-implement-ms-office-word-format-painter/CS/DXApplication9/Form1.cs#L85

csharp
DocumentRange selection = richEditControl.Document.Selection;
SubDocument subDocument = selection.BeginUpdateDocument();
sourceSelectedRange = subDocument.CreateRange(selection.Start, richEditControl.Document.Selection.Length);

winforms-richedit-document-api/CS/RichEditAPISample/CodeExamples/Export.cs#L64

csharp
// Get selection as plain text.
SubDocument docRange = document.Selection.BeginUpdateDocument();
string plainText = docRange.GetText(docRange.Range);

winforms-richeditcontrol-common-api/CS/RichEditAPISample/CodeExamples/RichEditControlActions.cs#L479

csharp
string s = new String('*', selLength);
SubDocument doc = range.BeginUpdateDocument();
doc.InsertSingleLineText(range.Start, s);

wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/TableActions.cs#L220

csharp
{
    SubDocument doc = cell.Range.BeginUpdateDocument();
    doc.InsertText(cell.Range.Start,

winforms-richedit-save-text-from-a-range-in-different-formats/VB/GetTextMethodsExample/Form1.vb#L28

vb
Dim selection As DevExpress.XtraRichEdit.API.Native.DocumentRange = richEditControl.Document.Selection
Dim doc As DevExpress.XtraRichEdit.API.Native.SubDocument = selection.BeginUpdateDocument()
mhtText = doc.GetMhtText(selection)

winforms-rich-edit-implement-ms-office-word-format-painter/VB/DXApplication9/Form1.vb#L77

vb
Dim selection As DocumentRange = richEditControl.Document.Selection
Dim subDocument As SubDocument = selection.BeginUpdateDocument()
sourceSelectedRange = subDocument.CreateRange(selection.Start, richEditControl.Document.Selection.Length)

winforms-richedit-document-api/VB/RichEditAPISample/CodeExamples/Export.vb#L57

vb
' Get selection as plain text.
Dim docRange As DevExpress.XtraRichEdit.API.Native.SubDocument = document.Selection.BeginUpdateDocument()
Dim plainText As String = docRange.GetText(docRange.Range)

winforms-richeditcontrol-common-api/VB/RichEditAPISample/CodeExamples/RichEditControlActions.vb#L497

vb
Dim s As New String("*"c, selLength)
Dim doc As SubDocument = range.BeginUpdateDocument()
doc.InsertSingleLineText(range.Start, s)

wpf-richedit-document-api/VB/DXRichEditControlAPISample/CodeExamples/TableActions.vb#L195

vb
Public Shared Sub MakeMultiplicationCell(ByVal cell As TableCell, ByVal i As Integer, ByVal j As Integer)
    Dim doc As SubDocument = cell.Range.BeginUpdateDocument()
    doc.InsertText(cell.Range.Start, String.Format("{0}*{1} = {2}", i + 2, j + 2, (i + 2) * (j + 2)))

See Also

Selection

DocumentRange Interface

DocumentRange Members

DevExpress.XtraRichEdit.API.Native Namespace