views:

206

answers:

1

I have searched on here and have not found exactly what I am looking for.

I am using a ContextMenuStrip, within this there is one menu item that is a checked/unchecked item. The structure is the following:

Top Level: Settings Middle Level: Processing Bottom Level: Manual processing

I can not find a way to access the Bottom level item, to set it as checked or unchecked.

Can anyone please help?

+3  A: 

Not sure I'm following the question. Do you know the name of the "Bottom level item"? If so just reference it by name:

bottomLevelMenuItem.Checked = true;

If you don't know the name you can loop through the Items or DropDownItems (depending on the MenuItem type) control collection to find the one you want.

foreach (ToolStripMenuItem stripItemCollection in MenuStrip.Items)
{
    ...
}

Edit:

Correct, ToolStripItem does not have a checked property. It is a base class for many tool strip objects, some of which do not support checking. In this case you are probably dealing with ToolStripMenuItems which do have a checked property.

Try this:

ToolStripMenuItem menuItem = this.cmuSystemTray.Items["TLSETTINGS"] as ToolStripMenuItem;
if (menuItem != null)
{
    menuItem.Checked = true;
}

Again though each Control (ToolStripMenuItem) has a name associated with it so it would be easier to use the original variable rather than going through the Items property of the context menu strip.

TLSETTINGS.Checked = true; // Assuming TLSETTINGS is the name
Cory Charlton
What I mean is do I do something like the following:ToolStripItem tItem = this.cmuSystemTray.Items["TLSETTINGS"]I tried the this.cmuSystemTray.Items["TLSETTINGS"] and .Checked was not a property that I could access
mattgcon
I apologize that was midleading to you all. Actually TLSETTINGS is the "name" for the top level menu item. The TLMANUAL item is within the TLSETTINGS drop down menu. So I need to reference the LTMANUAL item.Here is what I have and I am stuck:ToolStripItem tItem = this.cmuSystemTray.Items["TLSETTINGS"];From this point I cannot get the lower level items within the iItem Can anyone help or direct me to a good example online?
mattgcon
Ohhhhhh, nevermind I understand what you are talking about now, didn't know that was available to me. That makes it so much easier thank you for your help.
mattgcon