Skip to main content

PivotGridControl.BeginUpdate() Method

Locks the PivotGridControl object by preventing visual updates of the object and its elements until the EndUpdate method is called.

Namespace: DevExpress.XtraPivotGrid

Assembly: DevExpress.XtraPivotGrid.v24.2.dll

Declaration

public override void BeginUpdate()

Remarks

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.

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.

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;
        }
    }
}

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.

See Also