officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentrange-c845f643.md
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
SubDocument BeginUpdateDocument()
Function BeginUpdateDocument As SubDocument
| Type | Description |
|---|---|
| SubDocument |
A SubDocument instance allowing you to safely modify the document.
|
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.
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.
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);
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
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
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
// 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
string s = new String('*', selLength);
SubDocument doc = range.BeginUpdateDocument();
doc.InsertSingleLineText(range.Start, s);
wpf-richedit-document-api/CS/DXRichEditControlAPISample/CodeExamples/TableActions.cs#L220
{
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
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
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
' 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
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
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