Back to Devexpress

PivotGridControl.EndUpdate() Method

wpf-devexpress-dot-xpf-dot-pivotgrid-dot-pivotgridcontrol-92d3b49c.md

latest11.8 KB
Original Source

PivotGridControl.EndUpdate() Method

Unlocks the PivotGridControl object after a call to the BeginUpdate method and causes an immediate visual update.

Namespace : DevExpress.Xpf.PivotGrid

Assembly : DevExpress.Xpf.PivotGrid.v25.2.dll

NuGet Package : DevExpress.Wpf.PivotGrid

Declaration

csharp
public void EndUpdate()
vb
Public Sub

Remarks

See PivotGridControl.BeginUpdate to learn more.

To update PivotGridControl asynchronously, use the PivotGridControl.EndUpdateAsync method.

Example

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.

vb
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
xaml
<Window xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        x:Class="DXPivotGrid_BeginEndUpdate.MainWindow" 
        Height="600" Width="600" Title="Main Window">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <dxpg:PivotGridControl Name="pivotGridControl1" Grid.Row="1" Margin="10,0,10,10">
            <dxpg:PivotGridControl.Fields>
                <dxpg:PivotGridField Name="fieldA" FieldName="A" Area="RowArea"
                                     Caption="A" />
                <dxpg:PivotGridField Name="fieldB" FieldName="B" Area="ColumnArea"
                                     Caption="B" />
                <dxpg:PivotGridField Name="fieldData" FieldName="Data" Area="DataArea"
                                     Caption="Data" />
            </dxpg:PivotGridControl.Fields>
        </dxpg:PivotGridControl>
        <Grid Margin="10,10,10,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="310" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid Grid.Column="0">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <TextBlock TextWrapping="WrapWithOverflow">
                    Try transposing the pivot grid with and without locking
                    it, to see the difference in performance.
                </TextBlock>
                <Button x:Name="btnRun" Click="btnRun_Click" Grid.Row="1" Content="Transpose"
                        Width="75" Height="23" HorizontalAlignment="Left" />
            </Grid>
                <GroupBox Header="Pivot Grid Locking Options" Grid.Column="1" Margin="0,0,0,5">
                    <StackPanel Orientation="Vertical">
                        <RadioButton x:Name="rbLocked" Content="Lock the Pivot Grid"
                                     IsChecked="True" Margin="0,5,0,2" />
                        <RadioButton Content="Do Not Lock the Pivot Grid"
                                     Margin="0,2,0,5" />
                    </StackPanel>
                </GroupBox>
        </Grid>
    </Grid>
</Window>
csharp
using System;
using System.Data;
using System.Windows;
using DevExpress.Xpf.PivotGrid;

namespace DXPivotGrid_BeginEndUpdate {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            pivotGridControl1.DataSource = GetDataTable();
        }
        private void btnRun_Click(object sender, RoutedEventArgs e) {
            DateTime startTime = DateTime.Now;

            // If an appropriate option is enabled, 
            // locks the pivot grid to prevent further updates.
            if (rbLocked.IsChecked == true) pivotGridControl1.BeginUpdate();
            try {

                // Initiates transposition.
                Transpose();
            }
            finally {

                // If the pivot grid has been locked, unlocks it, allowing further updates.
                if (rbLocked.IsChecked == true) 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 == FieldArea.RowArea)
                    field.Area = FieldArea.ColumnArea;
                else if (field.Area == FieldArea.ColumnArea)
                    field.Area = FieldArea.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;
        }
    }
}

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.

wpf-pivot-grid-show-top-n-values-in-context-menu/CS/ContextMenuToShowTopN_Example/MainWindow.xaml.cs#L87

csharp
});
    valueItem.PivotGrid.EndUpdate();
}

wpf-pivot-grid-bind-to-an-mdb-database/CS/HowToBindToMDB/MainWindow.xaml.cs#L41

csharp
pivotGridControl1.EndUpdate();

wpf-pivot-grid-bind-to-an-olap-cube-net6/CS/HowToBindOLAP/MainWindow.xaml.cs#L42

csharp
pivotGridControl1.EndUpdate();
}

wpf-pivot-grid-show-top-n-values-in-context-menu/VB/ContextMenuToShowTopN_Example/MainWindow.xaml.vb#L84

vb
End Sub)
    valueItem.PivotGrid.EndUpdate()
End Sub

wpf-pivot-grid-bind-to-an-mdb-database/VB/HowToBindToMDB/MainWindow.xaml.vb#L36

vb
TryCast(orderDateBinding, DataSourceColumnBinding).GroupInterval = FieldGroupInterval.DateYear
    pivotGridControl1.EndUpdate()
End Sub

wpf-pivot-grid-bind-to-an-olap-cube-net6/VB/HowToBindOLAP/MainWindow.xaml.vb#L38

vb
pivotGridControl1.EndUpdate()
End Sub

See Also

BeginUpdate()

EndUpdateAsync

PivotGridControl Class

PivotGridControl Members

DevExpress.Xpf.PivotGrid Namespace