delphi中遍历MainMenu子菜单项到ListView中
展开全部
//这个是TreeView,不是ListView
//声明递归方法
//procedure aaaaa(mMenu: TMenuItem; nNode: TTreeNodes;p_node: TTreeNode);
procedure TForm1.aaaaa(mMenu: TMenuItem; nNode: TTreeNodes;p_node: TTreeNode);
var
i: Integer;
c_node: TTreeNode;
begin
for i := 0 to mMenu.Count - 1 do
begin
c_node := nNode.AddChild(p_node,mMenu.Items[i].Caption);
aaaaa(mMenu.Items[i],nNode,c_node); //递归
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
parent_node : TTreeNode;
begin
trv.Items.Clear;
for i:= 0 to MainMenu.Items.Count-1 do
begin
parent_node := trv.Items.Add(nil,MainMenu.Items[i].Caption);
aaaaa(MainMenu.Items[i],trv.Items, parent_node);
end;
end;
//声明递归方法
//procedure aaaaa(mMenu: TMenuItem; nNode: TTreeNodes;p_node: TTreeNode);
procedure TForm1.aaaaa(mMenu: TMenuItem; nNode: TTreeNodes;p_node: TTreeNode);
var
i: Integer;
c_node: TTreeNode;
begin
for i := 0 to mMenu.Count - 1 do
begin
c_node := nNode.AddChild(p_node,mMenu.Items[i].Caption);
aaaaa(mMenu.Items[i],nNode,c_node); //递归
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
parent_node : TTreeNode;
begin
trv.Items.Clear;
for i:= 0 to MainMenu.Items.Count-1 do
begin
parent_node := trv.Items.Add(nil,MainMenu.Items[i].Caption);
aaaaa(MainMenu.Items[i],trv.Items, parent_node);
end;
end;
展开全部
procedure MenuItemsToListView( mi : TMenuItem; lv : TListView );
var
i : Integer;
begin
for i := 0 to mi.Count - 1 do
begin
lv.AddItem( mi[i].Caption, nil );
MenuItemsToListView( mi[i], lv );
end;
end;
调用:MenuItemsToListView( MainMenu1, ListView1 );
var
i : Integer;
begin
for i := 0 to mi.Count - 1 do
begin
lv.AddItem( mi[i].Caption, nil );
MenuItemsToListView( mi[i], lv );
end;
end;
调用:MenuItemsToListView( MainMenu1, ListView1 );
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询