Frequent Data Updates
- 4 minutes to read
You can use one of the following techniques to optimize data updates within the GridControl:
- Speed up individual updates
- Process updates in batches
Speed Up Individual Updates
ChunkList
The ChunkList<T> suits applications where you handle large collection updates. The ChunkList might work slower than ordinary collections if you perform multiple operations that iterate over data source items (for example, summary calculation, data sort and filter operations).
We recommend that you use the ChunkList in the following case:
- The data source contains at least 10,000 elements.
- One update operation affects a batch of elements in a collection.
Optimized Summaries
The GridControl recalculates all records to update data summaries. To optimize an update operation, set the GridControl.OptimizeSummaryCalculation property to true. In this case, the GridControl calculates values only for changed records and updates data summaries according to these values. Therefore, the performance does not depend on the number of records.
We recommend that you optimize summary calculation in the following case:
- The GridControl is bound to an ObservableCollection<T> whose items implement the INotifyPropertyChanged and INotifyPropertyChanging interfaces.
- Columns with summaries are not unbound columns.
- You do not use custom summaries.
- You do not lock the GridControl to process updates in batches.
Process Updates in Batches
Data shaping operations allow you to sort, filter, and group data, and calculate summaries. The GridControl performs these operations when a data source change occurs. To process multiple updates as a single action, use one of the following methods:
Lock Updates
When you lock updates within the GridControl, a user cannot perform any data operations in the UI. You can process data updates and then apply all changes to the GridControl.
We recommend that you lock GridControl updates in the following case:
Your data source contains less than 100,000 elements. If the data source is too large, visible UI lags might appear.
A batch accumulates multiple updates.
Follow the steps below to apply this technique:
- Call the BeginDataUpdate method to lock data updates in the GridControl.
- Process multiple updates.
- Call the EndDataUpdate method to apply the changes.
The code sample below demonstrates how to prevent the GridControl from frequent updates when multiple data changes occur.
public void PerformUpdates() {
gridControl.BeginDataUpdate();
// Perform massive data updates...
gridControl.EndDataUpdate();
}
Refer to the following example if you want to call the BeginDataUpdate and EndDataUpdate methods in a MVVM application:
If you use the TreeListView, the GridControl processes hierarchical updates according to the data structure type:
- Self-Referential
- The GridControl ignores notifications from the data source and recreates nodes after an EndDataUpdate call.
- Hierarchical
- The GridControl handles notifications from the data source and updates node hierarchy after each change between BeginDataUpdate and EndDataUpdate method calls.
Call the TreeListView.BeginDataUpdate(bool recreateNodesOnEndDataUpdateOnly) and TreeListView.EndDataUpdate methods to manage hierarchical updates regardless of the data structure type. For example, if each change in the data source significantly affects node hierarchy, you may want to update it only once after an EndDataUpdate call. To do that, pass true as a parameter to the TreeListView.BeginDataUpdate(bool recreateNodesOnEndDataUpdateOnly) method.
Manual Refresh
Set the AllowLiveDataShaping property to false to allow the GridControl to ignore data shaping operations when data is changed. Call the RefreshData method to display all changes in the control.
We recommend that you force GridControl updates manually in the following case:
- You store data in the List<T> collection.
- Your data source contains less than 100,000 elements. If your source is too large, visible UI lags might appear.
- You refresh the GridControl on demand, but not after each change in the data source.
Automatic Refresh on a Timer
If your data changes frequently (for example, each millisecond), the GridControl does not have enough time to update its layout. You can perform the update operation on a timer. Implement a custom collection that blocks notifications about changes from the data source and copies data in the specified time interval. Changes in this collection trigger GridControl updates.
We recommend that you update data on a timer in the following case:
- Your data source contains less than 100,000 elements. If your source is too large and visible UI lags occur, you can increase the interval.
- You refresh the GridControl periodically, but not after each change in the data source.