T
tmaster
When I try to dynamically add a second sub menu item to this ContextMenu
item, I get an error 'Specified argument was out of the range of valid
values'.
Private Sub mnuTopics_Show_Select(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles mnuTopics_Show.Select
Dim mShowMenuItem As MenuItem
mShowMenuItem = DirectCast(sender, MenuItem)
mShowMenuItem.MenuItems.Clear()
' The first sub menu item gets added withouot any errors:
Dim mSubMenuItem As New MenuItem()
mSubMenuItem.Text = "Sub Item #1"
mSubMenuItem.Enabled = True
mSubMenuItem.Visible = True
AddHandler mSubMenuItem.Click, AddressOf MenuClickhandler
mShowMenuItem.MenuItems.Add(mSubMenuItem)
' This second sub menu item causes a problem:
mSubMenuItem.Text = "Sub Item #2"
mSubMenuItem.Enabled = True
mSubMenuItem.Visible = True
AddHandler mSubMenuItem.Click, AddressOf MenuClickhandler
'error occurs here:
mShowMenuItem.MenuItems.Add(mSubMenuItem)
End Sub
What am I doing wrong?
Thanks
item, I get an error 'Specified argument was out of the range of valid
values'.
Private Sub mnuTopics_Show_Select(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles mnuTopics_Show.Select
Dim mShowMenuItem As MenuItem
mShowMenuItem = DirectCast(sender, MenuItem)
mShowMenuItem.MenuItems.Clear()
' The first sub menu item gets added withouot any errors:
Dim mSubMenuItem As New MenuItem()
mSubMenuItem.Text = "Sub Item #1"
mSubMenuItem.Enabled = True
mSubMenuItem.Visible = True
AddHandler mSubMenuItem.Click, AddressOf MenuClickhandler
mShowMenuItem.MenuItems.Add(mSubMenuItem)
' This second sub menu item causes a problem:
mSubMenuItem.Text = "Sub Item #2"
mSubMenuItem.Enabled = True
mSubMenuItem.Visible = True
AddHandler mSubMenuItem.Click, AddressOf MenuClickhandler
'error occurs here:
mShowMenuItem.MenuItems.Add(mSubMenuItem)
End Sub
What am I doing wrong?
Thanks