windowsforms-devexpress-dot-xtrapivotgrid-dot-pivotgridcontrol-9aa0280c.md
Unlocks the PivotGridControl object after a call to the BeginUpdate method and causes an immediate visual update.
Namespace : DevExpress.XtraPivotGrid
Assembly : DevExpress.XtraPivotGrid.v25.2.dll
NuGet Package : DevExpress.Win.PivotGrid
public virtual void EndUpdate()
Public Overridable Sub
See PivotGridControl.BeginUpdate to learn more.
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.
using System;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraPivotGrid;
namespace XtraPivotGrid_BeginEndUpdate {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e) {
pivotGridControl1.DataSource = GetDataTable();
}
private void btnBegin_Click(object sender, EventArgs e) {
DateTime startTime = DateTime.Now;
// If an appropriate option is enabled,
// locks the pivot grid to prevent further updates.
if (rbLocked.Checked) pivotGridControl1.BeginUpdate();
try {
// Initiates transposition.
Transpose();
}
finally {
// If the pivot grid has been locked, unlocks it, allowing further updates.
if (rbLocked.Checked) pivotGridControl1.EndUpdate();
}
// Displays the amount of time taken by the transposition.
TimeSpan duration = DateTime.Now - startTime;
MessageBox.Show("Transposition took " +
duration.TotalSeconds.ToString("F2") + " seconds");
}
// Transposes the pivot grid by moving Row Fields to the Column Area, and vice versa.
private void Transpose() {
foreach(PivotGridField field in pivotGridControl1.Fields) {
if (field.Area == PivotArea.RowArea)
field.Area = PivotArea.ColumnArea;
else if (field.Area == PivotArea.ColumnArea)
field.Area = PivotArea.RowArea;
}
}
// Generates pivot grid data.
public static DataTable GetDataTable() {
DataTable table = new DataTable();
table.Columns.Add("A", typeof(string));
table.Columns.Add("B", typeof(string));
table.Columns.Add("Data", typeof(int));
for (int i = 0; i < 1000; i++)
for (int j = 0; j < 500; j++)
table.Rows.Add('A' + i.ToString(), 'B' + j.ToString(), ((int)i / 100));
return table;
}
}
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports DevExpress.XtraPivotGrid
Namespace XtraPivotGrid_BeginEndUpdate
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
pivotGridControl1.DataSource = GetDataTable()
End Sub
Private Sub btnBegin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnBegin.Click
Dim startTime As DateTime = DateTime.Now
' If an appropriate option is enabled,
' locks the pivot grid to prevent further updates.
If rbLocked.Checked Then
pivotGridControl1.BeginUpdate()
End If
Try
' Initiates transposition.
Transpose()
Finally
' If the pivot grid has been locked, unlocks it, allowing further updates.
If rbLocked.Checked 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 = PivotArea.RowArea Then
field.Area = PivotArea.ColumnArea
ElseIf field.Area = PivotArea.ColumnArea Then
field.Area = PivotArea.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
The following code snippets (auto-collected from DevExpress Examples) contain references to the EndUpdate() 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-pivot-grid-connect-to-an-olap-datasource/CS/WinOlapRetrieveFieldsExample/Form1.cs#L39
pivotGridControl1.Fields["[Measures].[Internet Sales Amount]"].Visible = true;
pivotGridControl1.EndUpdate();
// Unlocks the pivot grid and applies changes.
pivotGridControl1.EndUpdate();
}
}
pivotGridControl1.EndUpdate();
}
winforms-pivot-apply-summary-filter/CS/XtraPivotGrid_ApplySummaryFilter/Form1.cs#L32
finally {
pivotGridControl1.EndUpdate();
}
pivotGridControl1.Appearance.Lines.BackColor = Color.Transparent;
pivotGridControl1.EndUpdate();
winforms-pivot-grid-connect-to-an-olap-datasource/VB/WinOlapRetrieveFieldsExample/Form1.vb#L40
pivotGridControl1.Fields("[Measures].[Internet Sales Amount]").Visible = True
pivotGridControl1.EndUpdate()
' Resize columns automatically.
' Unlocks the pivot grid and applies changes.
pivotGridControl1.EndUpdate()
End Try
Next selectedElement
pivotGridControl1.EndUpdate()
End Sub
winforms-pivot-apply-summary-filter/VB/XtraPivotGrid_ApplySummaryFilter/Form1.vb#L33
Finally
pivotGridControl1.EndUpdate()
End Try
pivotGridControl1.Appearance.Lines.BackColor = Color.Transparent
pivotGridControl1.EndUpdate()
See Also