|
TBaseVirtualTree.OnCompareNodes Event
Sort and search support event.
Pascal
property OnCompareNodes: TVTCompareEvent;
Description
This event is the core event for all comparations between nodes. It is important that you write a handler for this event if you want to sort nodes!
Result must be set to less than 0 if Node1 is considered as being before Node2, equal to 0 if both a considered being the same and greater than 0 if the first node is considered as being after node 2. Keep in mind that you don't need to take sort direction into account. This is automatically handled by the tree. Simply return a comparation result as would there be an ascending sort order.
Below is some sample code taken from the Advanced Demo:
procedure TMainForm.VDT1CompareNodes(Sender: TBaseVirtualTree; Node1, Node2: PVirtualNode; Column: Integer; var Result: Integer); // used to sort the image draw tree var Data1, Data2: PImageData; begin Data1 := Sender.GetNodeData(Node1); Data2 := Sender.GetNodeData(Node2); // folder are always before files if Data1.IsFolder <> Data2.IsFolder then begin // one of both is a folder the other a file if Data1.IsFolder then Result := -1 else Result := 1; end else // both are of same type (folder or file) Result := CompareText(Data1.FullPath, Data2.FullPath); end;
See Also
SortTree, Sort
Class
Links
What do you think about this topic? Send feedback!
|