如何通过菜单项循环浏览子菜单 [英] How to loop through sub menu through menu items
本文介绍了如何通过菜单项循环浏览子菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想遍历所有菜单项并将这些项置于Treeview中.为此,我使用了以下代码.
信息
我有交易"菜单,并且有购买"菜单,而购买菜单有
(购买发票,收货单等).我想让该商品进入Treeview,正在交易中,应该有购买,正在购买中的应该有购买发票,并且收货很好.
我怎样才能做到这一点..?
请帮帮我.
谢谢
I want to loop through all menu items and put the items to treeview. I used following code for this purpose.
inforamtion
I have Transaction Menu and it has a Purchase Menu and purchase menu have
(Purchase invoice, Good Receive Note, etc). I want to get this items to treeview, under transaction, should have purchase and under purchase should have purchase invoice and good receive note
How can I do this..?
Please help me.
Thanks
private void GetControlByName()
{
for (int i = 0; i < this.menuStrip1.Items.Count; i++)
{
string mnuItemName = this.menuStrip1.Items[i].Text;
Tree.Nodes.Add("", mnuItemName, 0, 2);
ToolStripMenuItem tmpMenuItem = this.menuStrip1.Items[i] as ToolStripMenuItem;
for (int j = 0; j < tmpMenuItem.DropDownItems.Count; j++)
{
string menuSubItem = tmpMenuItem.DropDownItems[j].Text;
if (menuSubItem != "")
{
Tree.Nodes[i].Nodes.Add("", menuSubItem, 1, 2);
}
}
}
Tree.ExpandAll();
}
推荐答案
您需要编写递归函数.例如,递归 [ http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.nodes.aspx [ ^ ]
http://stackoverflow.com/questions/881607/adding-child-nodes-in-treeview [^ ]
http://msdn.microsoft.com/en-us/library/aa984278%28v = vs.71%29.aspx [ ^ ]
You need to write recursive function. For example, recursion[^] is used to enumerate folders on the hard disc.
More about Treeview:
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.nodes.aspx[^]
http://stackoverflow.com/questions/881607/adding-child-nodes-in-treeview[^]
http://msdn.microsoft.com/en-us/library/aa984278%28v=vs.71%29.aspx[^]
这篇关于如何通过菜单项循环浏览子菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文