首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

用foreach进行遍历时,出现异常

2011-12-21 
用foreach进行遍历时,出现错误!用foreach进行遍历时,出现以下错误:foreach语句无法对“System.Windows.Form

用foreach进行遍历时,出现错误!
用foreach进行遍历时,出现以下错误:
  foreach   语句无法对“System.Windows.Forms.MenuItem”类型的变量操作,因为“System.Windows.Forms.MenuItem”不包含“GetEnumerator”的定义,或它是不可访问的
错误代码:
private   void   ImageExplorer_Load(object   sender,   System.EventArgs   e)
{
foreach(MenuItem   temp   in   this.menuItem8)
    {
          this.contextMenu1.MenuItems.Add(temp.CloneMenu());
      }
}
请各位大虾帮帮忙,谢谢。

[解决办法]
menuItem8.menuitems

[解决办法]
因为MenuItem不是一个集合所以不能对它进行遍历,你应该对它的子菜单集合操作.
[解决办法]
private void ImageExplorer_Load(object sender, System.EventArgs e)
{
foreach(MenuItem temp in this.menuItem8.MenuItems)
{
this.contextMenu1.MenuItems.Add(temp.CloneMenu());
}
}
[解决办法]
同意这个
private void ImageExplorer_Load(object sender, System.EventArgs e)
{
foreach(MenuItem temp in this.menuItem8.MenuItems)
{
this.contextMenu1.MenuItems.Add(temp.CloneMenu());
}
}

热点排行