Locks the PivotGridControl object by preventing visual updates of the object and its elements until the EndUpdate method is called.
The BeginUpdate and EndUpdate methods allow you to avoid flickering while performing batch modifications to the PivotGridControl‘s settings. Once the BeginUpdate method has been called, modifying settings of the PivotGridControl and its elements does not cause an immediate visual update. So, multiple modifications can be made to the object and its elements without a major impact on performance or screen flickering. After all the desired operations have been finished, call the EndUpdate method.
The BeginUpdate and EndUpdate methods use an internal counter to implement the update functionality. The counter’s initial value is 0. Visual updates are forbidden if the counter’s value is greater than 0, and the updates are enabled if the counter’s value is 0. The BeginUpdate method increments the counter. The EndUpdate method decrements the counter. If the counter’s new value is 0, an immediate visual update occurs. Each call to BeginUpdate must be paired with a call to EndUpdate. To ensure that EndUpdate is always called even if an exception occurs, use the try…finally statement.
The following example demonstrates how to lock the pivot grid, thus preventing it from being redrawn while a sequence of operations that affect its appearance and/or functionality is being performed.In this example, the pivot grid is transposed by moving Row Fields to the Column Area, and vice versa. Prior to this, the BeginUpdate method is called to lock the pivot grid. When the transposition is completed, the pivot grid is unlocked via the EndUpdate method. To ensure that the EndUpdate method is always called even if an exception occurs, calls to the BeginUpdate and EndUpdate methods are wrapped in a try…finally statement.
Imports Microsoft.VisualBasic Imports System Imports System.Data Imports System.Windows Imports DevExpress.Xpf.PivotGrid Namespace DXPivotGrid_BeginEndUpdate Partial Public Class MainWindow Inherits Window Public Sub New() InitializeComponent() pivotGridControl1.DataSource = GetDataTable() End Sub Private Sub btnRun_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Dim startTime As DateTime = DateTime.Now ' If an appropriate option is enabled, ' locks the pivot grid to prevent further updates. If rbLocked.IsChecked = True Then pivotGridControl1.BeginUpdate() End If Try ' Initiates transposition. Transpose() Finally ' If the pivot grid has been locked, unlocks it, allowing further updates. If rbLocked.IsChecked = True Then pivotGridControl1.EndUpdate() End If End Try ' Displays the amount of time taken by the transposition. Dim duration As TimeSpan = DateTime.Now.Subtract(startTime) MessageBox.Show("Transposition took " & duration.TotalSeconds.ToString("F2") & " seconds") End Sub ' Transposes the pivot grid by moving Row Fields to the Column Area, and vice versa. Private Sub Transpose() For Each field As PivotGridField In pivotGridControl1.Fields If field.Area = FieldArea.RowArea Then field.Area = FieldArea.ColumnArea ElseIf field.Area = FieldArea.ColumnArea Then field.Area = FieldArea.RowArea End If Next field End Sub ' Generates pivot grid data. Public Shared Function GetDataTable() As DataTable Dim table As New DataTable() table.Columns.Add("A", GetType(String)) table.Columns.Add("B", GetType(String)) table.Columns.Add("Data", GetType(Integer)) For i As Integer = 0 To 999 For j As Integer = 0 To 499 table.Rows.Add("A"c + i.ToString(), "B"c + j.ToString(), (CInt(Fix(i)) / 100)) Next j Next i Return table End Function End Class End Namespace