473,395 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ContextMenuStrip and submenus - virtual impossibility??? huh?

I have a context menu strip. I can Add elements to its "Items", but there is
nothing in there to add a sub context menu strip.

Menu
Item 1
Item 2
Sub Item 1 <-- impossible to add!

How do I achieve that? There seems no API's to do that and the internet is
simply "empty" when it comes to that. All newsgroups questions are
unanswered. Does. Are we witnessing the death of the sub-menu here?

Ron
Oct 30 '06 #1
1 2554
Ron M. Newman wrote:
I have a context menu strip. I can Add elements to its "Items", but there is
nothing in there to add a sub context menu strip.

Menu
Item 1
Item 2
Sub Item 1 <-- impossible to add!

How do I achieve that? There seems no API's to do that and the internet is
simply "empty" when it comes to that. All newsgroups questions are
unanswered. Does. Are we witnessing the death of the sub-menu here?
In order to have sub items, you need to use a ToolStripMenuItem class
to do it:

private void button1_Click(object sender, EventArgs e)
{
ContextMenuStrip cs = new ContextMenuStrip();
cs.Items.Add("Menu Item 1");
cs.Items.Add("Menu Item 2");

//This is the item we want to have sub items, so we need to create
it manually
//so that we can add items to it later
ToolStripMenuItem tm = new ToolStripMenuItem("Menu Item with Sub
Items");
cs.Items.Add(tm);

//Here we add sub items to the ToolStripMenuItem that we added
earlier
tm.DropDownItems.Add("Sub Item 1");
tm.DropDownItems.Add("Sub Item 2");

ToolStripMenuItem tm1 = new ToolStripMenuItem("More Sub Items");
tm.DropDownItems.Add(tm1);

tm1.DropDownItems.Add("Sub Sub Item 1");
tm1.DropDownItems.Add("Sub Sub Item 2");

//Set the buttons ContextMenuStrip property to the context menu we
just created.
button1.ContextMenuStrip = cs;
}

Incidentally, if you drag a ContextMenuStrip to the form, you can
design the menu visually and then look at the generated code to see how
it is done.

Chris

Oct 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Neelesh | last post by:
I wanted to know why member templates cannot be virtual - is it because there is a conceptual impossibility in having them, or is it because the current mechanism of implementaing virtual functons...
7
by: Dave | last post by:
How do I get my ContextMenuStrip to receive key down preview events? I have the event hooked but I don't see the key strokes in the event? Dave
5
by: =?Utf-8?B?cHJvZ2dlcg==?= | last post by:
I've written an application that can minimize to the tray and can reappear if you double click on the icon in the tray (ShowInTaskbar is set to false). I've also created a ContextMenuStrip (Visual...
0
by: active | last post by:
For the last 3 or 4 days I've been, on an off, searching the Internet and theVS2005 Doc for an example of how to add a contextmenustrip to a menustrip. I can move all the items from a...
1
by: =?Utf-8?B?QnJhZA==?= | last post by:
i have a menu system that is generated dynamically everything works good except for one minor astetic.... I click on a menu item that displays a ContextMenuStrip Popup Menu If an item on...
1
by: =?Utf-8?B?TGVudXNpYQ==?= | last post by:
In my program I dynamically create treeViews and dynamically add nodes to them. To each node I attach ContextMenuStrip which suppose allow delete selected node e.t.c. How from inside click...
7
by: Joe Cool | last post by:
Let's say I have a Treeview control on a form. Each leaf node in the Treeview has a ContextMenuStrip, each with one ToolStripMenuItem, and all ToolStripMenuItems Click event is handled by a comment...
9
by: =?Utf-8?B?Z2luYWNyZXNzZQ==?= | last post by:
Hi, I have a form (Form1) with a ContextMenuStrip (ContextMenuStrip1). If I pass Form1 to a Utility Sub with the following code: Public Sub Utility(theForm as Object) with theForm For Each...
2
by: eBob.com | last post by:
I've been working on an app which has an array of RichTextBoxes. And I have a context menu for the RTBs. The context menu has two levels; the first level has two items, "Load Sample Text File"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.