删除TreeView节点以及其子节点

//1.删除TreeView节点以及其子节点
procedure TForm2.Button1Click(Sender: TObject);
var TreeNode:TTreeNode;
begin
  if TreeView1.Selected <> Nil then
  Begin
    TreeNode := TreeView1.Selected.getFirstChild;
    while TreeNode <> nil do
    begin
      TreeNode.Delete;
      TreeNode := TreeView1.Selected.getFirstChild;
    end;
  end;
end;


//2.判断是否有子节点
procedure TForm2.Button2Click(Sender: TObject);
begin
  if TreeView1.Selected.HasChildren then
  begin
    ShowMessage('有子节点');
  end;
end;

posted on 2015-07-13 15:02  疯狂delphi  阅读(1581)  评论(0编辑  收藏  举报

导航