Anel Hodzic Anel Hodzic - 3 months ago 37x Question

MenuStrip items Enable/Disable

How to programaticaly Enable or Disable MenuStrip items.

Example if i have this

enter image description here

I want to disable the item2 and item3. Tried with

MenuStrip1.Items("Item 1").Enabled = False
MenuStrip1.Items(2).Enabled = False


Going by the image, it appears you want to disable/enable things in the dropdown.

Each top level menu item is itself an object which contains the actual drop down items - the MenuStrip is just a container for them. So, if I have a File | View | Tools menu, there will be three ToolStripMenuItems to work with, each with a DropDownItems collection of those entries. So:

ViewMenuItem.DropDownItems(2).Enabled = False

This disables the 3rd dropdown item on the View menu. Yours might be named ItemsToolStripMenuItem. The UI designer doesn't use a key to create/add new dropdown items, so the string overload wont work unless you are adding them manually:

' create new DD item
Dim foo = New ToolStripMenuItem("Foo", Nothing, 
              AddressOf FooToolStripMenuItem_Click, "Foo")
' add to menu

' access by key
ViewMenuItem.DropDownItems("Foo").Enabled = True