I’m working with a large TMSFNCTreeView; the sample data I’m working with has 70,000 nodes and I’ve run into speed issue when moving nodes (in order to sort them). That’s a lot of nodes, but I’m only sorting the sub-nodes that are immediately under the currently selected node. Level 1 of the treeview has just 150 nodes and it takes several minutes to sort it with a simple bubble sort. So I put together the following code which results in each node being moved just one time and yet it still takes about 15 seconds to sort those 150 nodes:
MyList:=tStringlist.create;
MyList.Sorted:=true;
TreeView1.BeginUpdate;
for y:=0 to (TreeView1.selectedNode.nodes.count-1) do
MyList.AddObject(TreeView1.selectedNode.nodes[y].text[0] TreeView1.SelectedNode.Nodes[y]);
for y:=0 to (MyList.count-1) do
TTMSFNCTreeViewNode(MyList.Objects[y]).MoveTo(TreeView1.SelectedNode);
TreeView1.EndUpdate;
(this is sorting alphabetically but I’ll need to sort on other criteria once this is working efficiently)
The delay is almost entirely in that second loop that’s just moving each of the 150 nodes to its correct index. It seems odd that the move process takes that long because it doesn’t take that long to create the nodes in the first place. Is there a more time-efficient way to change the order of these nodes?