Jump to content


dougwinsby

Member Since 23 Apr 2019
Offline Last Active Apr 28 2023 02:17 AM
-----

Topics I've Started

Delete Top-Level Selected Node and all Children

22 May 2019 - 05:13 AM

 I was trying to delete a "selected" top-level node along with all its children (from code).
 
I first tried: 

props.SelectedNode.ClearChildren;
But that only deleted some of the children (and of course, not the selected node).
 
I tried these two other methods, but without success:

props.Nodes.ClearChildren(oNode);
propsPriceSheet.Nodes.Delete(0);

If finally tried something like the following, which worked, but seems more difficult than it should be:


oParent := props.SelectedNode;
for i:= pred(props.Nodes.Count) downto 0 do
begin
  oNode := props.Nodes[i];
  if oNode.ParentNode = oParent then oNode.Free;
end;
oParent.Free;

Am I missing a better way?