使用TTreeview作为菜单

1 delphi

我使用delphi的ttreeview作为'选项'菜单.我将如何在运行时选择下一个节点,如上一个和下一个按钮?我尝试了getprev和getnext方法,但没有运气.

Joh*_*mas 5

在这里你有'下一步'的行为.对于'上一页',我将为您留下锻炼:--)

procedure TForm8.btn1Click(Sender: TObject);  
var  
  crt: TTreeNode;

begin
  with tv1 do //this is our tree
  begin
    if Selected=nil then
      crt:=Items[0] //the first one
    else
      crt:=Selected.GetNext; //for previous you'll have 'GetPrev' 

    if crt<>nil then //can be 'nil' if we reached to the end
      Selected:=crt;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

HTH