[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications, and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Collapse]Vertical Grid
   [Expand]Binding to Data
   [Expand]Data Layout: Records, Rows and Cells
   [Expand]Data Editing and Validation
    Formatting Values
   [Expand]Drag and Drop
   [Expand]Appearance and Custom Painting
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Hit Information
    Batch Modifications
   [Expand]Member Tables
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Batch Modifications

Batch modifications are designed to speed up a grid control's performance by eliminating superfluous visual and data updates. The main objective is to update the grid control only once - after all the necessary changes have been made.

Expanded Preventing Excessive Visual Updates

Every time you change a property or call a method that affects a grid's visual appearance, it is updated to reflect its new state. In some cases, changing a property only affects the corresponding display element, not the entire grid control, and so only this element is repainted. In most cases however, modifying a property or calling a method affects an entire grid control, and therefore the grid is updated. To update a grid, the VGridControlBase.LayoutChanged method is called.

If you perform a sequence of modifications that cause grid updates, you may notice that performance suffers, especially when these operations are time-consuming. For instance, deleting multiple records may take a while, because the grid is updated after every deletion. However, you can speed up this operation by preventing unnecessary updates between individual operations. The grid control provides several methods to support these batch modifications.

Before applying a series of changes to a grid, you can call the VGridControlBase.BeginUpdate method. This locks the grid and prevents subsequent visual updates. After you've performed all the necessary operations on a grid, call the VGridControlBase.EndUpdate or VGridControlBase.CancelUpdate method. The EndUpdate method immediately updates the grid to reflect all recent changes, and re-enables it for future updates. The CancelUpdate method re-enables the grid control for future updates, but it does not cause an immediate visual update.

The BeginUpdate and EndUpdate/CancelUpdate methods use an internal counter to implement the appropriate functionality. The counter has an initial value of 0. Each call to the BeginUpdate method increments this counter by one. Each call to the EndUpdate/CancelUpdate method decrements this counter by one and if its new value is zero, the grid is updated. Note that each call to BeginUpdate must be paired with a call to EndUpdate/CancelUpdate. If you call BeginUpdate, but forget to call EndUpdate/CancelUpdate afterwards or EndUpdate/CancelUpdate isn't called because an exception occurred, the grid will no longer be refreshed. To ensure that EndUpdate/CancelUpdate is always called even when an exception occurs, use the try...finally statement.

Expanded Example

The sample code below shows an example of using the batch modifications technique. The SetRowsHeight method can be used to prevent the vertical grid from being updated while changing the height of its rows.

Expanded Preventing Excessive Internal Data Updates

The BeginUpdate and EndUpdate methods prevent only visual updates. When you change a property or call a method within a BeginUpdate and EndUpdate pair, the corresponding actions take effect immediately. However, the results are displayed only after EndUpdate has been called.

Some operations you may perform force the grid control to reload data. Each of these operations causes an internal data update, and when such operations are performed in a sequence, multiple data updates occur. Excessive data updates cannot be avoided by using the BeginUpdate and EndUpdate methods. Instead, the VGridControlBase.BeginDataUpdate and VGridControlBase.EndDataUpdate methods must be used. These methods improve a control's performance when a sequence of any of the following operations is performed:

  • adding, deleting, or modifying records at the data source level.

If the code that performs a sequence of any of these operations is wrapped with the BeginDataUpdate and EndDataUpdate methods, the grid will perform only a single data update reflecting all changes made after the EndDataUpdate method is called.

Use the BeginDataUpdate and EndDataUpdate methods in a similar way to the BeginUpdate and EndUpdate methods. Each call to the BeginDataUpdate method must correspond to a call to the EndDataUpdate method. To ensure that this happens (even if an exception occurs), use the try...finally block.

The BeginDataUpdate and EndDataUpdate methods call the BeginUpdate and EndUpdate methods, respectively. So, you don't need to call these methods to prevent superfluous visual updates when using the BeginDataUpdate and EndDataUpdate methods.

Is this topic helpful?​​​​​​​