How can I hide a subitem of an item from a menu (menuStrip) in vb
Try this one but tell me it's out of range
MenuStrip1.Items.Item(1).Enabled = False
Try this code and hide me is the full menu
MenuStrip1.Items(0).Visible = False
How can I hide a subitem of an item from a menu (menuStrip) in vb
Try this one but tell me it's out of range
MenuStrip1.Items.Item(1).Enabled = False
Try this code and hide me is the full menu
MenuStrip1.Items(0).Visible = False
The Menus and submenus have their property Name
and you can access them directly. Let's say you have a Menu called Menu1
and below it a submenu called Submenu1
. To hide the submenu you simply have to do:
Submenu1ToolStripMenuItem.Visible=false
Normally by default the name is the text of the menu + ToolStripMenuItem
, but you can modify it to whatever you want.
Edit
I give you a couple more options in case you want to hide a submenu with respect to the parent menu:
'Oculta el primer submenu con respecto al menu llamado Menu1ToolStripMenuItem
CType(Me.MenuStrip1.Items("Menu1ToolStripMenuItem"), ToolStripMenuItem).DropDownItems.Cast(Of ToolStripMenuItem).ElementAt(0).Visible = False
'Oculta el submenu llamado Submenu1ToolStripMenuItem del Menu1ToolStripMenuItem
CType(Me.MenuStrip1.Items("Menu1ToolStripMenuItem"), ToolStripMenuItem).DropDownItems.Cast(Of ToolStripMenuItem).Where(Function(s) s.Name = "Submenu1ToolStripMenuItem").FirstOrDefault().Visible = False