Back to Devexpress

RichEditDocumentServer.BeginUpdate() Method

officefileapi-devexpress-dot-xtrarichedit-dot-richeditdocumentserver-6b111c8f.md

latest5.9 KB
Original Source

RichEditDocumentServer.BeginUpdate() Method

Locks the RichEditDocumentServer object until the RichEditDocumentServer.EndUpdate method is called.

Namespace : DevExpress.XtraRichEdit

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

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
public void BeginUpdate()
vb
Public Sub BeginUpdate

Remarks

Enclose your code in the BeginUpdate - EndUpdate() method calls to improve performance when you apply multiple modifications to a document.

Each call to BeginUpdate must be paired with the EndUpdate() call. You can use the try…finally statement to ensure that EndUpdate() is always called even if an exception occurs.

The following example shows how to use the BeginUpdate - EndUpdate() methods.

csharp
// Create a new RichEditDocumentServer instance.
RichEditDocumentServer richEditDocumentServer = new RichEditDocumentServer();

richEditDocumentServer.BeginUpdate();
try
{
    // Create a multiplication table.
    Table table = richEditDocumentServer.Document.Tables.Create(richEditDocumentServer.Document.Selection.Start, 8, 8, AutoFitBehaviorType.AutoFitToWindow);

    table.Borders.InsideHorizontalBorder.LineThickness = 1;
    table.Borders.InsideHorizontalBorder.LineStyle = BorderLineStyle.Double;
    table.Borders.InsideVerticalBorder.LineThickness = 1;
    table.Borders.InsideVerticalBorder.LineStyle = BorderLineStyle.Double;
    table.TableAlignment = TableRowAlignment.Center;

    table.ForEachCell((cell, rowIndex, columnIndex) =>
    {
        richEditDocumentServer.Document.InsertText(cell.Range.Start, String.Format("{0}*{1} = {2}",
             columnIndex + 2, rowIndex + 2, (rowIndex + 2) * (columnIndex + 2)));
    });

}
finally
{
    richEditDocumentServer.EndUpdate();
}
vb
' Create a new RichEditDocumentServer instance.
Dim richEditDocumentServer As New RichEditDocumentServer()

richEditDocumentServer.BeginUpdate()
Try
    ' Create a multiplication table.
    Dim table As Table = richEditDocumentServer.Document.Tables.Create(richEditDocumentServer.Document.Selection.Start, 8, 8, AutoFitBehaviorType.AutoFitToWindow)

    table.Borders.InsideHorizontalBorder.LineThickness = 1
    table.Borders.InsideHorizontalBorder.LineStyle = BorderLineStyle.Double
    table.Borders.InsideVerticalBorder.LineThickness = 1
    table.Borders.InsideVerticalBorder.LineStyle = BorderLineStyle.Double
    table.TableAlignment = TableRowAlignment.Center

    table.ForEachCell(Sub(cell, rowIndex, columnIndex)
                           richServer.Document.InsertText(cell.Range.Start, String.Format("{0}*{1} is {2}",
                                                        columnIndex + 2, rowIndex + 2, (rowIndex + 2) * (columnIndex + 2)))
                       End Sub)

Finally
    richEditDocumentServer.EndUpdate()
End Try

The following code snippets (auto-collected from DevExpress Examples) contain references to the BeginUpdate() 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.

word-document-api-use-printablecomponentlink-to-print-document/CS/PrintingSystem/Form1.cs#L23

csharp
// Insert a field displaying the current date/time into the document header.
srv.BeginUpdate();
SubDocument _header = srv.Document.Sections[0].BeginUpdateHeader();

word-document-api-invoke-print-preview-dialog/VB/Form1.vb#L33

vb
'Create a table
richServer.BeginUpdate()
Dim _table As Table = richServer.Document.Tables.Create(richServer.Document.Selection.Start, 8, 8, AutoFitBehaviorType.FixedColumnWidth)

word-document-api-use-printablecomponentlink-to-print-document/VB/PrintingSystem/Form1.vb#L23

vb
' Insert a field displaying the current date/time into the document header.
srv.BeginUpdate()
Dim _header As SubDocument = srv.Document.Sections(0).BeginUpdateHeader()

See Also

EndUpdate()

IsUpdateLocked

RichEditDocumentServer Class

RichEditDocumentServer Members

DevExpress.XtraRichEdit Namespace