TreeList.BeginSort() Method
Prevents the tree structure from being changed when changing specific options affecting the order of nodes, until the TreeList.EndSort method is called.
Namespace: DevExpress.XtraTreeList
Assembly: DevExpress.XtraTreeList.v24.1.dll
NuGet Packages: DevExpress.Win.Navigation, DevExpress.Win.TreeList
Declaration
Remarks
The Tree List control enables you to sort data against values of multiple columns. When sorting columns, the control rearranges its nodes. In addition, when columns are sorted, changing node values can also cause node re-sorting. So, when performing such operations multiple times simultaneously, the control will be updated multiple times. To prevent multiple excessive updates and improve painting speed and overall performance, use the BeginSort and TreeList.EndSort methods.
A BeginSort method call locks the Tree List control’s sorting operations. Any changes made after this method is called do not cause immediate node rearrangement and control repainting. To unlock the control and apply the changes, call the TreeList.EndSort method.
The BeginSort and EndSort methods call the TreeList.BeginUpdate and TreeList.EndUpdate internally. So, the BeginSort and EndSort methods also prevent excessive visual updates, and there is no need to use the BeginUpdate and EndUpdate methods to do this.
The BeginSort and EndSort methods do not prevent the Tree List control’s excessive internal updates when nodes are added or deleted, when a node’s parent is changed or when the control’s underlying data source is modified. To prevent excessive updates in these cases, in bound mode, use the TreeList.LockReloadNodes and TreeList.UnlockReloadNodes methods, and in unbound mode, use the TreeList.BeginUnboundLoad and TreeList.EndUnboundLoad methods.
To unlock control redrawing after it has been locked by the TreeList.BeginSort
method, without causing an immediate visual update, call TreeList.CancelSort method.
Example
The following code sorts data against the Department and Budget columns. The TreeList.BeginSort
and TreeList.EndSort methods wrap the code to avoid superfluous updates.
using DevExpress.XtraTreeList.Columns;
//...
treeList1.BeginSort();
treeList1.Columns["Department"].SortOrder = SortOrder.Ascending;
treeList1.Columns["Budget"].SortOrder = SortOrder.Descending;
treeList1.EndSort();