Expanding nodes in a TShellTreeView lazarus / 31-LCL ---------------------------------------------------------------------- petevick · 2022-02-03 11:52 I have the following code, which I came across on here and can't find it now!!, in a project that expands a named node in a TShellTreeView, but it only seems to work on the first level nodes... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  procedure TForm1.NodeByText(ToDo:String; aNodeText:String);var  vNode : TTreeNode;  vLastNode : TTreeNode;begin  for vNode in TreeView.Items do begin    if vNode.Text = aNodeText then begin      vLastNode := vNode;      vNode.Selected := True;    end;  end;    vLastNode.Expanded:=True;end; ...I've tried modifying it to include all node levels but I keep on getting errors. I would be grateful for any help before I loose more of what little hair I have. ---------------------------------------------------------------------- BrunoK · 2022-02-03 12:13 Quote from: petevick on February 03, 2022, 12:52:19 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     vLastNode.Expanded:=True;Try (untested) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     vLastNode.Expand({Recurse=}True); ---------------------------------------------------------------------- petevick · 2022-02-03 12:21 Quote from: BrunoK on February 03, 2022, 01:13:46 pmTry (untested) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     vLastNode.Expand({Recurse=}True);I'm pretty sure that won't work as the code ends at last first level node before that line ---------------------------------------------------------------------- balazsszekely · 2022-02-03 13:57 @petevick When you loop through the nodes and expand a particular node inside loop, you will reach the end(items.count) sooner.  Use Node.First, Node.Next instead: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure ExpandNode(SW: TShellTreeView; ANodeName: String);var  Node : TTreeNode;begin  Node := SW.Items.GetFirstNode;  while Node <> nil do  begin    if Node.Text = ANodeName then      Node.Expand(True);    Node := Node.GetNext;  end;end; ---------------------------------------------------------------------- petevick · 2022-02-03 14:04 Quote from: GetMem on February 03, 2022, 02:57:35 pm@petevick When you loop through the nodes and expand a particular node inside loop, you will reach the end(items.count) sooner.  Use Node.First, Node.Next instead: Well that looks easy enough, even I can make out the flow  Thanks yet again GetMem ---------------------------------------------------------------------- BrunoK · 2022-02-03 14:44 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i vLastNode.Expanded;expands the vLastNode direct children. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i vLastNode.Expand({Recurse=}True);.Expand(True) as proposed in my entry and used by GetMem recursively expand vLastNode and all its children. I think that GetMem's code will needlessly scan subtrees that may have already have been fully expanded.