• TreeView 节点多选,对TreeView的遍历


    ====================================

    需要设置multiselect=true;multiselstyle设置为[mscontrolselect]

    procedure TUserRightSet.BitBtn8Click(Sender: TObject);
    var
      TNode,Cnode: TTreeNode;
      i: Integer;
      iLoop: Boolean;
    begin
      Cnode:= self.TreeView1.Selected;
      if not Cnode.Expanded then Exit;
      if Cnode.HasChildren then
      begin
        TNode:= Cnode.getFirstChild;
        TNode.Selected:= True;
        iLoop:= True;
        while iLoop do
        begin
          TNode:= TNode.GetNext;
          TreeView1.Select(TNode,[ssCtrl]);
          if TNode = Cnode.GetLastChild then Break;
        end;
      end;
    end;

    ====================================

    var
        Selections:   TObjectList;
        I:   Integer;
    begin
        Selections   :=   TObjectList.Create(False);
        TreeView1.GetSelections(Selections);
        for   I   :=   0   to   Selections.Count   -   1   do
            memo1.Lines.Add(TTreeNode(Selections[I]).Text);
        Selections.Free;
    end

    摘 要:对TreeView的遍历
    关键字:TreeView
    类 别:Delphi & IDE
    E-Mail:iloveyou9595@sina.com

    function TForm1.AllOverTreeView(node:TTreenode):TTreenode;
    begin
      while node<>nil do
        begin
          if node.HasChildren then
            begin
              node:=node.getFirstChild;
              allovertreeview(node);
              node:=node.Parent;
            end;
          if node.getNextSibling<>nil then
            node:=node.getNextSibling
          else
            exit;
        end;
    end;


    可以遍历某个节点下的所有节点。
    procedure TForm1.Button1Click(Sender: TObject);
    var
      parentnode:TTreenode;
    begin
      parentnode:=Mytreeview.Items.GetFirstNode;
      AllOverTreeView(parentnode);
    end;

    function treeallnode(anode:Ttreenode):string;
     var
     i:integer;
     mystr:string;
    begin
    for i:=0 to anode.Count-1 do
     begin
     if mystr<>'' then
     mystr:=mystr+'|'+trim(trim(anode[i].Text))
     else
     xxx:=trim(trim(anode[i].Text));
     if anode[i].HasChildren then
      if mystr<>'' then
       mystr:=mystr+'|'+trim(treeallnode(anode[i]))
      else
       mystr:=trim(treeallnode(anode[i]));
    end;
    result:=mystr;
    end;

    ================================

    delphi treeview 遍历所有子集节点

    procedure TForm1.BitBtnClick(Sender: TObject);
      procedure treeCldnode(Anode: TTreeNode);
      var
        i: integer;
        node: TTreeNode;
      begin

        for i := 0 to Anode.Count - 1 do
        begin
         ShowMessage(Anode.Item[i].Text);
          Node := ANode.Item[i];
          if (node.Count > 0)   then
            treeCldnode(Node);

        end;
      end;
    var
      i: integer;
      node: TTreeNode;
    begin
      node := TreeView1.Selected;
       treeCldnode(node);

    end;

  • 相关阅读:
    三联生活周刊:女游戏设计师之死
    HTML
    营运社区所需要的基本心理学常识
    对C++下struct 和 类默认继承的认识
    什么是列表?
    什么是个人网站?
    DevExpress ASPxListBox can't get selected items after postback
    ListItemEventHandler does not fire on the prospective list
    SPF和SharePoint Server的区别
    什么是网站?
  • 原文地址:https://www.cnblogs.com/mingdep/p/2411922.html
Copyright © 2020-2023  润新知