Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MenuStrip items Enable/Disable vb.net

Tags:

vb.net

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
like image 799
Anel Hodzic Avatar asked Feb 02 '26 19:02

Anel Hodzic


1 Answers

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
ViewMenuItem.DropDownItems.Add(foo)

' access by key
ViewMenuItem.DropDownItems("Foo").Enabled = True
like image 125
Ňɏssa Pøngjǣrdenlarp Avatar answered Feb 05 '26 13:02

Ňɏssa Pøngjǣrdenlarp