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;

参考
http://www.cnblogs.com/yilongm/archive/2013/01/16/2863546.html
posted @ 2017-03-28 18:02  夏天的西瓜君  阅读(1252)  评论(0编辑  收藏  举报