Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Contect Menu Strip 1

Status
Not open for further replies.

ChewDoggie

Programmer
Mar 14, 2005
604
US
Hello,

I have a context menu strip and the menu has "Items" in it, but it also has, what I call, "Sub Items". The "Items" are

"New ..." (ItemIndex 0)
Line Separator (ItemIndex 1)
"Edit >" (ItemIndex 2)

Beneath "Edit" there a another list of "Sub Items":
"Personal Info ..."
"Contact Info ..."
"Department ..."
"Status ..."

I can access the first layer of Items ("New" and "Edit") with:

Code:
cmsAssociates.Items[ItemIndex].Enabled = true;

I cannot, for the sake of me, figure out how to programmatically access the second layer of Items ("Personal", "Contact", etc).

Any help would be appreciated.

Chew


10% of your life is what happens to you. 90% of your life is how you deal with it.
 
Have you tried something like this

Code:
	foreach(MenuItem mi in contextMenu1.MenuItems)
	{
		Console.WriteLine(mi.Text);
		foreach(MenuItem si in mi.MenuItems)
		{
			Console.WriteLine(si.Text);
		}
	}

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
You got me started. I've modified your code slightly to look like this:

Code:
            foreach (ToolStripMenuItem mi in cmsAssociates.Items)
                {
                MessageBox.Show("Menu Item: " + mi.Name);
                foreach (ToolStripMenuItem si in mi.DropDownItems)
                    {
                    MessageBox.Show("Sub Menu: " + si.Name);
                    }
                }

but it blew up when it encountered a ToolStripSeparator, which I'll handle myself.

Thanks for the good pointer as to where to begin ! I wouldn't have gotten anywhere without it !

Chew




10% of your life is what happens to you. 90% of your life is how you deal with it.
 
Glad to help.

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top