Skip to main content

TcxCustomTreeView.SortType Property

Specifies the type of sorting applied to tree view control nodes

Declaration

property SortType: TSortType read; write; default stNone;

Property Value

Type Default
TSortType stNone

Remarks

Use the SortType property to sort tree view control nodes and specify when they need to be resorted. The following values are available for this property.

Value

Meaning

stNone

Specifies that sorting is not applied tree view nodes. This means that the control will not automatically resort nodes until the SortType property is set to another value. However, nodes can still be sorted programmatically by calling the AlphaSort or CustomSort method.

Changing the SortType property to stNone when nodes are already sorted will not restore the original order of items. If you need to restore original node order, the best is to save the node layout at application startup using the SaveToFile or SaveToStream methods. Then, nodes can be reloaded using the LoadFromFile and LoadFromStream method when needed.

stText

Specifies that tree view nodes are sorted by their captions in ascending order. Each time the caption of a node is changed, nodes are resorted. To toggle sort order, call the AlphaSort method.

You can implement custom sorting logic by handling the OnCompare event. In this instance, the stText value merely implies that nodes need to be resorted each time a node caption changes. Thus you must use this value if the sorting logic only uses node captions (the Text property) to perform node comparison. The resulting sort order depends upon the implementation of the OnCompare event handler.

stData

Setting the SortType property doesn’t apply any predefined sort order to nodes. This value merely implies that node resorting must be invoked each time the value of a node’s Data property is changed. The sorting logic must be implemented by handling the OnCompare event.

Set the SortType property to stData if you implement sorting that is based on the Data property value of nodes and does not depend on its Text property value. If the sorting algorithm uses both properties, set the SortType property to stBoth.

stBoth

This value implies that node sorting takes place each time the Text or Data property of a node is changed. The sorting logic must be implemented in the OnCompare event handler. Use the stBoth value if your sorting algorithm uses both the Text and Data properties of nodes to perform node comparison. If only the Text or Data property is used, set the SortType property to stText or stData respectively.

You may need to use a sorting procedure that uses custom node settings (other than the Text or Data property) to perform sorting. In this instance, you must leave the SortType property set to stNone to disable automatic node restoration when changing the mentioned properties. When settings used in your sorting algorithm are changed or nodes are added to the tree view, you must manually call the AlphaSort method. Use the OnAddition method to provide a response to node addition.

Please refer to the OnCompare method description for an example of performing custom node sorting.

Warning

When nodes are sorted, their indexes within the tree view are changed. Thus accessing nodes by indexes after sorting may lead to errors.

The default value of the SortType property is stNone.

See Also