TTreeView不必Expand,用 Items也是可以访问所有的节点的。可以试一下以下代码:
窗口上放置 1. TreeView1: TTreeView; 2. Edit1: TEdit; 3.Button1: TButton;
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
ANode : TTreeNode;
bStart : Boolean;
begin
bStart := False;
ANode := nil;
for i := 0 to TreeView1.Items.Count - 1 do begin
ANode := TreeView1.Items;
if bStart and (CompareText(ANode.Text, Edit1.Text) = 0) then begin
ANode.Selected := True;
TreeView1.SetFocus;
Exit;
end;
bStart := bStart or (ANode = TreeView1.Selected);
end;
if i = TreeView1.Items.Count then
ShowMessage(Edit1.Text + ' Not Found');
end;
当然,也可以用遍历方法来查找节点,但用在这里有点杀鸡用牛刀了