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

Tips (1547)

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

OpenTools API (3)
Printing (35)
Strings (83)
System (268)
VCL (243)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

33 Visitors Online


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

Tip Rating (9):  
     


// 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