====================================
需要设置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;