windowsforms-devexpress-dot-xtraspreadsheet-dot-spreadsheetcontrol-c7128a4b.md
Locks the SpreadsheetControl to prevent its visual updates until the SpreadsheetControl.EndUpdate method is called.
Namespace : DevExpress.XtraSpreadsheet
Assembly : DevExpress.XtraSpreadsheet.v25.2.dll
NuGet Package : DevExpress.Win.Spreadsheet
public void BeginUpdate()
Public Sub BeginUpdate
Enclose your code in the BeginUpdate - SpreadsheetControl.EndUpdate method calls to suppress the SpreadsheetControl’s visual updates and improve its performance when you perform multiple changes to a spreadsheet document.
Each call to BeginUpdate must be paired with the SpreadsheetControl.EndUpdate call. The BeginUpdate method locks the SpreadsheetControl, so that it is not rendered after each modification. The SpreadsheetControl.EndUpdate method unlocks the control to enable all the changes to take effect. You can use the try…finally statement to ensure that SpreadsheetControl.EndUpdate is always called even if an exception occurs.
The following example shows how to use the BeginUpdate - SpreadsheetControl.EndUpdate methods.
spreadsheetControl1.BeginUpdate();
try
{
Worksheet worksheet = spreadsheetControl1.Document.Worksheets[0];
spreadsheetControl1.Unit = DevExpress.Office.DocumentUnit.Point;
// Create a multiplication table.
worksheet.Cells["A1"].Value = "*";
for(int i = 1; i < 11; i++)
{
// Create a header column.
worksheet.Columns["A"][i].Value = i;
// Create a header row.
worksheet.Rows["1"][i].Value = i;
}
// Multiply values of header cells.
worksheet.Range["B2:K11"].Formula = "=B$1*$A2";
// Obtain the data range.
CellRange tableRange = worksheet.GetDataRange();
// Specify the row height and column width.
tableRange.RowHeight = 40;
tableRange.ColumnWidth = 40;
// Align the table content.
tableRange.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
tableRange.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
// Fill the header cells.
CellRange headerCells = worksheet.Range.Union(worksheet.Range["A1:K1"], worksheet.Range["A2:A11"]);
headerCells.FillColor = Color.FromArgb(0xf7, 0x9b, 0x77);
headerCells.Font.Bold = true;
// Fill cells that contain multiplication results.
worksheet.Range["B2:K11"].FillColor = Color.FromArgb(0xfe, 0xf2, 0xe4);
}
finally
{
spreadsheetControl1.EndUpdate();
}
spreadsheetControl1.BeginUpdate()
Try
Dim worksheet As Worksheet = spreadsheetControl1.Document.Worksheets(0)
spreadsheetControl1.Unit = DevExpress.Office.DocumentUnit.Point
' Create a multiplication table.
worksheet.Cells("A1").Value = "*"
For i As Integer = 1 To 10
' Create a header column.
worksheet.Columns("A")(i).Value = i
' Create a header row.
worksheet.Rows("1")(i).Value = i
Next i
' Multiply values of header cells.
worksheet.Range("B2:K11").Formula = "=B$1*$A2"
' Obtain the data range.
Dim tableRange As CellRange = worksheet.GetDataRange()
' Specify the row height and column width.
tableRange.RowHeight = 40
tableRange.ColumnWidth = 40
' Align the table content.
tableRange.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center
tableRange.Alignment.Vertical = SpreadsheetVerticalAlignment.Center
' Fill the header cells.
Dim headerCells As CellRange = worksheet.Range.Union(worksheet.Range("A1:K1"), worksheet.Range("A2:A11"))
headerCells.FillColor = Color.FromArgb(&Hf7, &H9b, &H77)
headerCells.Font.Bold = True
' Fill cells that contain multiplication results.
worksheet.Range("B2:K11").FillColor = Color.FromArgb(&Hfe, &Hf2, &He4)
Finally
spreadsheetControl1.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.
winforms-spreadsheet-import-data-from-a-datatable-instance/CS/Form1.cs#L26
spreadsheetControl1.BeginUpdate();
activeWorksheet.Import(ManualDataSet.CreateData().Tables[0], true, selection.TopRowIndex, selection.LeftColumnIndex);
winforms-spreadsheet-use-custom-cell-editors/CS/DevAVInvoicing/Form1.cs#L180
void AddRecord(Worksheet sheet) {
spreadsheetControl1.BeginUpdate();
try {
winforms-spreadsheet-chart-api/CS/SpreadsheetChartAPISamples/Form1.cs#L127
{
spreadsheet.BeginUpdate();
codeEditor.BeforeCompile();
winforms-spreadsheet-pivot-table-api/CS/SpreadsheetPivotTableExamples/Form1.cs#L115
{
spreadsheet.BeginUpdate();
codeEditor.BeforeCompile();
Private Sub BindingManager_CurrentChanged(ByVal sender As Object, ByVal e As EventArgs)
_control?.BeginUpdate()
Try
winforms-spreadsheet-import-data-from-a-datatable-instance/VB/Form1.vb#L29
spreadsheetControl1.BeginUpdate()
activeWorksheet.Import(ManualDataSet.CreateData().Tables(0), True, selection.TopRowIndex, selection.LeftColumnIndex)
winforms-spreadsheet-use-custom-cell-editors/VB/DevAVInvoicing/Form1.vb#L167
Private Sub AddRecord(ByVal sheet As Worksheet)
spreadsheetControl1.BeginUpdate()
Try
winforms-spreadsheet-chart-api/VB/SpreadsheetChartAPISamples/Form1.vb#L123
Private Sub evaluator_OnBeforeCompile(ByVal sender As Object, ByVal e As EventArgs)
spreadsheet.BeginUpdate()
codeEditor.BeforeCompile()
winforms-spreadsheet-pivot-table-api/VB/SpreadsheetPivotTableExamples/Form1.vb#L109
Private Sub evaluator_OnBeforeCompile(ByVal sender As Object, ByVal e As EventArgs)
spreadsheet.BeginUpdate()
codeEditor.BeforeCompile()
See Also