whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

88 Visitors Online


 
...search a TreeView Item through its Text property?
Autor: Jürgen Poley
Homepage: no
[ Print tip ]  

Tip Rating (11):  
     


// Search a TreeItem through its Text property
// Return value is a TreeNodeObject

// TreeItem über die TextEigenschaft  suchen
// Der Rückgabewert der Function ist ein TreeNodeObject.

function Form1.TreeItemSearch(TV: TTreeView; SucheItem: string): TTreeNode;
var
  
i: Integer;
  iItem: string;
begin
  if 
(TV = nilor (SucheItem = '') then Exit;
  for i := 0 to TV.Items.Count - 1 do 
  begin
    
iItem := TV.Items[i].Text;
    if SucheItem = iItem then 
    begin
      
Result := TV.Items[i];
      Exit;
    end 
    else 
    begin
      
Result := nil;
    end;
  end;
end;


//  Example: Search for Wasserfall in TreeView1 and select item

//  Beispiel: Sucht in TreeView1 das
//  Item mit der Beschriftung  >Wasserfall< u. selectiert es;
procedure TForm1.Button1Click(Sender: TObject);
var
  
Node: TTreeNode;
begin
  
//either - entweder so
  
Node := TreeItemSuchen(TreeView1, 'Wasserfall');
  TreeView1.Selected := Node;

  //or - oder so
  
TreeView1.Selected := TreeItemSuchen(TreeView1, 'Wasserfall ');
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners