删除子菜单项时出现GettingError [英] GettingError when remove child menu items

查看:80
本文介绍了删除子菜单项时出现GettingError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试删除子菜单项时出现错误.
错误:索引超出范围.必须为非负数并且小于集合的大小.参数名称:index
看到我的代码
-------------
将mnuItems设置为新的MenuItem()
昏暗的MenuItems作为MenuItemCollection = NavMenu.Items
将MasterItem调暗为新的MenuItem()
对于每个menuItem作为menuItem中的MenuItem
如果menuItem.Value ="First"然后
MasterItem = menuItem
如果结束
如果menuItem.Value ="Second"然后
mnuItems.ChildItems.Remove(mnuItems.ChildItems(0))''''此处出现错误.
如果结束
下一个
menuItems.Remove(MasterItem)
错误:
索引超出范围.必须为非负数并且小于集合的大小.
参数名称:index

I am getting error when i am trying to remove child menu items.
Error : Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
see my code
-------------
Dim mnuItems As New MenuItem()
Dim menuItems As MenuItemCollection = NavMenu.Items
Dim MasterItem As New MenuItem()
For Each menuItem As MenuItem In menuItems
If menuItem.Value = "First" Then
MasterItem = menuItem
End If
If menuItem.Value = "Second" Then
mnuItems.ChildItems.Remove(mnuItems.ChildItems(0)) ''''Getting Error here.
End If
Next
menuItems.Remove(MasterItem)
Error :
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

推荐答案

Try
if (mnuItems.ChildItems.Count >0) Then mnuItems.ChildItems.Remove(mnuItems.ChildItems(0)
Try
if (mnuItems.ChildItems.Count >0) Then mnuItems.ChildItems.Remove(mnuItems.ChildItems(0)


这篇关于删除子菜单项时出现GettingError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆