unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
TreeView1: TTreeView;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure ReadTreeViewData(tnNode:TTreeNode;strCondition:AnsiString);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ReadTreeViewData(tnNode:TTreeNode;strCondition:AnsiString);
var
tnCurrent:TTreeNode;
i:integer;
begin
//其中tnNode为树的节点,strCondition为查找的内容
if(tnNode.Text=strCondition) then
tnNode.Selected:=true;
if(tnNode.Count<>0) then
begin
for i:=0 to tnNode.Count-1 do
ReadTreeViewData(tnNode.Item,strCondition);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TreeView1.MultiSelect:=true;
ReadTreeViewData(TreeView1.Items.GetFirstNode,'1');
end;
end.