Board index » delphi » Find item in TreeView

Find item in TreeView

Hi, All!

I am beginner in Delphi 4.
I have a problem: how to find an item in Treeview and make it selected,
if I have only item text?
Can anybody help me?

Thanks, Igor.

 

Re:Find item in TreeView


Quote
>I am beginner in Delphi 4.
>I have a problem: how to find an item in Treeview and make it selected,
>if I have only item text?
>Can anybody help me?

>Thanks, Igor.

procedure SelectNode(const Tx: string; Tree: TTreeView);
var
  node : TTreeNode;
begin            
  if Tx = '' then exit;
  node := Tree.GetFirst; {get the top node / items[0]}
  while (node <> nil) do begin
    if CompareText(Tx, node.Text) = 0 then begin
      Tree.Selected := node;
      node.MakeVisible;
      break;
    end else node := node.GetNext; {get the next node}
  end;                                                              
end;

Chris
c8...@aol.com

Re:Find item in TreeView


In article <19990326222441.04277.00000...@ng-cf1.aol.com>, c8...@aol.com

Quote
(C8591) writes:
>>I am beginner in Delphi 4.
>>I have a problem: how to find an item in Treeview and make it selected,
>>if I have only item text?
>>Can anybody help me?

>>Thanks, Igor.

>procedure SelectNode(const Tx: string; Tree: TTreeView);
>var
>  node : TTreeNode;
>begin            
>  if Tx = '' then exit;
>  node := Tree.GetFirst; {get the top node / items[0]}
>  while (node <> nil) do begin
>    if CompareText(Tx, node.Text) = 0 then begin
>      Tree.Selected := node;
>      node.MakeVisible;
>      break;
>    end else node := node.GetNext; {get the next node}
>  end;                                                              
>end;

Don't forget that unless the TTreeView has focus, or TTreeView.HideSelection is
set to false, then the selection with not be highlit. Default setting of
HideSelection is true.

Alan Lloyd
alangll...@aol.com

Other Threads