ColumnView.BeginDataUpdate() Method
Prevents visual and internal data updates until the BaseView.EndDataUpdate method is called.
Namespace: DevExpress.XtraGrid.Views.Base
Assembly: DevExpress.XtraGrid.v24.1.dll
NuGet Packages: DevExpress.Win.Grid, DevExpress.Win.Navigation
Declaration
Remarks
If a sequence of actions which affects the View’s appearance needs to be performed, the code should be enclosed between calls to the BaseView.BeginUpdate and BaseView.EndUpdate methods. These methods allow the View to be locked, so that updates to the visual controls don’t occur when multiple changes are performed in sequence.
However, the BeginUpdate and EndUpdate methods do not prevent internal data updates. To prevent internal data updates, use the BeginDataUpdate and BaseView.EndDataUpdate methods. These allow improved grid control performance when performing a sequence of any of the following operations:
- sorting or grouping by a column;
- modifying the View’s records when data is sorted;
- 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 View will perform only a single data update, reflecting all changes made, after the EndDataUpdate method is called.
The BeginDataUpdate and EndDataUpdate methods call the BeginUpdate and EndUpdate methods internally. This prevents the View from being updated visually.
When Grid Control is bound to a data source implementing the IBindingList interface. It automatically subscribes to the IBindingList.ListChanged event. This allows the grid to respond to changes made on the data source level. The BeginDataUpdate method temporarily unsubscribes the grid control from this event. The EndDataUpdate method, when called, subscribes the grid control to this event once again.
Do not add columns to the data source between BeginDataUpdate and EndDataUpdate method calls, as the grid control will not properly respond to these changes. This action may also raise exceptions. In addition, do not reassign a data source between BeginDataUpdate and EndDataUpdate method calls.
Note
Do not call the BeginDataUpdate and EndDataUpdate methods in master-detail mode if any detail is currently open, as this can cause some painting artifacts.
Please refer to the Batch Modifications Overview topic, for additional information.
The ColumnView.BeginSort and ColumnView.EndSort methods are equivalent to the BeginDataUpdate and BaseView.EndDataUpdate methods.
Example
The following example sorts data by two columns in a Grid View.
The code is enclosed within calls to the ColumnView.BeginDataUpdate
and BaseView.EndDataUpdate methods. This speeds up performance by sorting the data only once, after the BaseView.EndDataUpdate method is called.
gridView1.BeginDataUpdate();
try {
gridView1.ClearSorting();
gridView1.Columns["Trademark"].SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
gridView1.Columns["Model"].SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;
}
finally {
gridView1.EndDataUpdate();
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the BeginDataUpdate() 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.