Author: Tomas Rutkauskas
I would like to compare the items in a TStringList with the child nodes of the
selected node in a TTreeView and instead of deleting the matching nodes, change the
image of the node to one from a TImageList component.
Answer:
Solve 1:
Something like:
1 var2 T: TTreeNode;
3 begin4 {Point at the first child of the selected node}5 T := TreeView.Selected.GetFirstChild;
6 {Loop over all children of this node}7 while Assigned(T) do8 begin9 {Compare T.Text against contents of a listbox, or whatever...}10 {T set to nil if Selected has no more children}11 T := TreeView.Selected.GetNextChild(T);
12 end;
13 end;
Note this only works with direct children of the Selected node; if you may have to
deal with deeper levels in the tree then it gets (marginally) more complex.
Solve 2:
Try one of these:
14 { ... }15 for i := 0 to TreeView1.Selected.Count - 1 do16 if ListBox1.Items.IndexOf(TreeView1.Selected.Item[i].Text) >= 0 then17 TreeView1.Selected.Item[i].ImageIndex := 4;
18 { ... }19 20 var21 child: TTreeNode;
22 { ... }23 child := TreeView1.Selected.GetFirstChild;
24 while Assigned(child) do25 begin26 if ListBox1.Items.IndexOf(child.Text) >= 0 then27 child.ImageIndex := 4;
28 child := child.GetNextSibling
29 end;