Question

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?

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top