日期:2014-05-18  浏览次数:20844 次

从菜单中提取名称加入tree中的问题.
为实现从将菜单提取到树中的操作,但发现当菜单中存在separator(分割条)时会由于类型错误报错,请教该如何在循环时过滤掉separator而将菜单正确的提取出来?
----------------------------------
public   void   TreeRoot(ref   TreeView   myT,Form   myForm)
{

foreach(MenuItem   myMI   in   myForm.Menu.MenuItems   )
{
TreeNode   myTreeN   =   new   TreeNode();
myTreeN.Text=myMI.Text;
TreeNod(myMI,myTreeN,false);
myT.Nodes.Add(myTreeN);
}
myT.ShowRootLines=true;
myT.SelectedNode=myT.Nodes   [0];
myT.Focus();
}
public   TreeNode   TreeNod(System.Windows.Forms.MenuItem   m,TreeNode   asTN,bool   asbl)
{
TreeNode   TreeN1   =   new   TreeNode();
//if   (asbl   &&   m.Text!=System.Convert.ToString( '- '))
if   (asbl)
{
TreeN1.Text=m.Text;
asTN.Nodes.Add(TreeN1);
}
else
{
TreeN1=asTN;
}
foreach(System.Windows.Forms.MenuItem   subm   in   m.MenuItems)
{
TreeNod(subm,TreeN1,true);
}
return   TreeN1;
}

------解决方案--------------------
不懂WinForm