How to change menu items in a menustrip


I have a menustrip and added 3 menuitems in the designer

I want to change one of the menu items to .Enabled = true

How can I access the menuitem?

the menuitem is the 3rd one

dont know if you can help me?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


You can access doing this:

           this.menuStrip1.Items[3].Enabled = true;

Hope it helps...
this.menuStrip1.Items[3].Enabled = true;

Open in new window

mousemat24Author Commented:
I get

index was out of range. must be non-negative and less then size of collection. Parameter name:index

Please note:

I have one menu item:

  Save As

Dont know why i get an error?
Umar Topia.Net Full Stack DeveloperCommented:
Index is always 0 based in .Net

so, to access 3rd menu item, you could use

this.menuStrip1.Items[3].Enabled = true;
this.menuStrip1.Items[3].Enabled = true;

Open in new window

OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Umar Topia.Net Full Stack DeveloperCommented:
Sry abt the previous post

you should use
this.menuStrip1.Items[2].Enabled = true;

Open in new window

than you need this:
((ToolStripMenuItem)menuStrip1.Items[0]).DropDownItems[2].Enabled = false;

where the zero is "file" and the two is "Save As"
Remember arrays atart counting at zero.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mousemat24Author Commented:
I ttried your solution umartopia but it didnt work, Chicovsky solution worked as I expected, I think it needed the DropDownItems[2].

thanks for your help, both of you guys
The index for the menuItems are 0 based, so the third item should be indexed as 2.
But as you have 4 items, acessing index 3 shouldn"t return an error.

Can you post some of your code here so we can have a look at it?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.