Back to Devexpress

DocumentRange.EndUpdateDocument(SubDocument) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentrange-dot-endupdatedocument-x28-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-subdocument-x29.md

latest8.3 KB
Original Source

DocumentRange.EndUpdateDocument(SubDocument) Method

Finalizes modifications of 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
void EndUpdateDocument(
    SubDocument document
)
vb
Sub EndUpdateDocument(
    document As SubDocument
)

Parameters

NameTypeDescription
documentSubDocument

A SubDocument instance obtained via the previously called DocumentRange.BeginUpdateDocument method.

|

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 EndUpdateDocument method implements this requirement.

Example

The following code replaces the selected text with asterisks.

The RichEditControl instance is passed to the BarItem.ItemClick event handler using the BarItem.Tag property.

View Example

vb
Private Shared Sub buttonCustomAction_ItemClick_Replace(ByVal sender As Object, ByVal e As ItemClickEventArgs)
    Dim richEdit As RichEditControl = TryCast(e.Item.Tag, RichEditControl)
    Dim range As DocumentRange = richEdit.Document.Selection
    Dim selLength As Integer = range.Length
    Dim s As New String("*"c, selLength)
    Dim doc As SubDocument = range.BeginUpdateDocument()
    doc.InsertSingleLineText(range.Start, s)
    Dim rangeToRemove As DocumentRange = doc.CreateRange(range.Start, selLength)
    doc.Delete(rangeToRemove)
    range.EndUpdateDocument(doc)
End Sub
csharp
static void buttonCustomAction_ItemClick_Replace(object sender, ItemClickEventArgs e) {
    RichEditControl richEdit = e.Item.Tag as RichEditControl;
    DocumentRange range = richEdit.Document.Selection;
    int selLength = range.Length;
    string s = new String('*', selLength);
    SubDocument doc = range.BeginUpdateDocument();
    doc.InsertSingleLineText(range.Start, s);
    DocumentRange rangeToRemove = doc.CreateRange(range.Start, selLength);
    doc.Delete(rangeToRemove);
    range.EndUpdateDocument(doc);
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the EndUpdateDocument(SubDocument) 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#L34

csharp
mhtText = doc.GetMhtText(selection);
    selection.EndUpdateDocument(doc);
}

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

csharp
sourceSelectedRange = subDocument.CreateRange(selection.Start, richEditControl.Document.Selection.Length);
    selection.EndUpdateDocument(subDocument);
}

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

csharp
string plainText = docRange.GetText(docRange.Range);
document.Selection.EndUpdateDocument(docRange);

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

csharp
doc.Delete(rangeToRemove);
    range.EndUpdateDocument(doc);
}

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

csharp
String.Format("{0}*{1} = {2}", i + 2, j + 2, (i + 2) * (j + 2)));
    cell.Range.EndUpdateDocument(doc);
}

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

vb
mhtText = doc.GetMhtText(selection)
    selection.EndUpdateDocument(doc)
Else

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

vb
sourceSelectedRange = subDocument.CreateRange(selection.Start, richEditControl.Document.Selection.Length)
    selection.EndUpdateDocument(subDocument)
End Sub

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

vb
Dim plainText As String = docRange.GetText(docRange.Range)
document.Selection.EndUpdateDocument(docRange)
DevExpress.XtraEditors.XtraMessageBox.SmartTextWrap = True

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

vb
doc.Delete(rangeToRemove)
    range.EndUpdateDocument(doc)
End Sub

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

vb
doc.InsertText(cell.Range.Start, String.Format("{0}*{1} = {2}", i + 2, j + 2, (i + 2) * (j + 2)))
    cell.Range.EndUpdateDocument(doc)
End Sub

See Also

Selection

DocumentRange Interface

DocumentRange Members

DevExpress.XtraRichEdit.API.Native Namespace