Delphi 简单方法搜索定位TreeView项

procedure TFmXX.BtnFindClick(Sender: TObject);
var
  i : integer;
begin
  inherited;
  for i := 0 to BTvCity.Items.Count -1 do
  begin
   {如果和文本框匹配}
    if BTvCity.Items[i].Text = EdtNodeText.Text then
    begin
      {有父类的时候通过关闭展开父类让Tv自动定位}
      if  BTvCity.Items[i].Parent <> nil then
      begin
        BTvCity.Items[i].Parent.Expanded := False;
        BTvCity.Items[i].Parent.Expanded := True;
      end
      else
      begin
       {通过关闭展开父类让Tv自动定位}
        BTvCity.Items[i].Expanded := False;
        BTvCity.Items[i].Expanded := True;
      end;
     {选择当前循环项,并退出循环,不然他会循环到最后浪费}
      BTvCity.Items[i].Selected := True;
      Break;
    end;
  end;
end;

 

posted on 2013-01-16 23:20  哈哈哈哈BBA  阅读(3931)  评论(0编辑  收藏  举报

导航