How can I hide the subitem of an item from a menuStrip in vb?

1

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
    
asked by Acd 03.05.2017 в 02:33
source

2 answers

1

Your IDE shows you the name of your item in the property area

in this case my item is called

ToolStripMenuItem6

now only access your visible property:

ToolStripMenuItem6.Visible = False
    
answered by 03.05.2017 / 20:14
source
-1

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
    
answered by 03.05.2017 в 11:13