Dynamically change the Sort order in a TVirtualTreeView

293 views Asked by At

I want to be able to turn Sorting on and off in TVirtualTreeView. At present I am using OnCompareNode to sort do the actual sorting as is standard practice. This is my code under OnCompareNode.

procedure TfmCodeExplorerVT.vtCodeExplrCompareNodes(Sender: TBaseVirtualTree;
  Node1, Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
Var CodeData0: PItemRecord;
    CodeData1: PItemRecord;
begin
    if Sender.GetNodeLevel(Node1) = 0 then exit;
    CodeData0 := vtCodeExplr.GetNodeData(Node1);
    CodeData1 := vtCodeExplr.GetNodeData(Node2);
    if Sorted then
      Result := CompareText(CodeData0.Caption, CodeData1.Caption);
end;

I have a button which I can toggle between Sorted and Unsorted.

How do I get any expanded nodes in the VirtualTreeView to update dynamically? The only way I have found so far is to Collapse the open node and Expand it again. Is that the correct way?

0

There are 0 answers