How to change menu items in a menustrip

Hi

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?

thanks
mousemat24Asked:
Who is Participating?
 
ChicovskyCommented:
Ok
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.
0
 
ChicovskyCommented:
Hi,

You can access doing this:

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

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

Open in new window

0
 
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:

File
  Open
  Save
  Save As
  Exit

Dont know why i get an error?
 
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
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

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

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

Open in new window

0
 
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
0
 
felipe_schauenburgCommented:
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?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.