Mirror

Find items in a TTreeView (Views: 100)


Problem/Question/Abstract:

How can I find a TTreeView item by string parameter? I mean like TreeNode := indexOf(Item: String);

Answer:

If you want to track the HTREEITEM ItemID's then you could use GetNode. To search by text you'll need to go through the list. Here is a quick option, depends on what you are looking to do.

{ ... }
Form1.TreeView.Items.BeginUpdate;
for count := 1 to Form1.TreeView.Items.Count do
  if (Form1.TreeView.Items.Item[count - 1].Text = 'Text') then
  begin
    {your code here;}
    {Break;}
  end;
finally
  Form1.TreeView.Items.EndUpdate;
end;

<< Back to main page