473,395 Members | 1,678 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.

Merge two contextmenustrips to a single tree node

I have create two separate contextmenu strips on a windows form. Now i want to display both these combined on to a tree node. Is this possible?
e.g.
First strip: Add, Subtract
Second strip: multiply, divide.

When I right click on a tree node the menu should display Add,subtract,multiply and divide.

I know that
treeView.Nodes[3].Nodes[2].ContextMenuStrip= firststrip;
will disply the first one only. I want to do something like this
treeView.Nodes[3].Nodes[2].ContextMenuStrip= firststrip+secondstrip
Mar 10 '10 #1

✓ answered by GaryTexmo

Hmm, it looks like those ToolStripMenuItems can only belong to one context menu at a time. You're absolutely correct, when you add from one list to the other, it just removes itself. I dug around MSDN and I don't see why this is.

Either way, all you need to do is create a copy of each one you find and then add it to your merged list.

I found a couple of resources on merging context menus. There's a ToolStripManager.Merge method that does this, but it also seems to remove the items from the source and put them in the new location. So I think your best bet, if you want to maintain both lists, is to create a copy.

(Link that might interest you: http://social.msdn.microsoft.com/For...4-3346d0749b00)

6 5015
tlhintoq
3,525 Expert 2GB
You will have to programmatically add all off the ContextMenuItems from menu 1 and menu 2 into a new menu 3, then show that. A simple 'for' loop construct should do it.
Mar 10 '10 #2
I tried this but doesnt work. Do you find any error in this code?

Expand|Select|Wrap|Line Numbers
  1.        private ContextMenuStrip mMergeContextMenuStrips(params ContextMenuStrip[] list)
  2.         {
  3.             ///
  4.             /// Merges contextmenustrips  and return a new strip
  5.             ///
  6.             ContextMenuStrip MergeContextMenuStrip = new ContextMenuStrip();
  7.             for (int i = 0; i < list.Length; i++)
  8.             {
  9.                 for (int j=0; j< list[i].Items.Count; j++)
  10.                 {
  11.                     MergeContextMenuStrip.Items.Add(list[i].Items[j]);
  12.                 }
  13.             }
  14.             return MergeContextMenuStrip;
  15.         }
Mar 11 '10 #3
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Mar 11 '10 #4
GaryTexmo
1,501 Expert 1GB
*** EDIT ***
If you read my first post, ignore it :D I didn't notice you were passing an array of ContextMenuStrip objects to your method.

Here's a better question, what doesn't work about it? It crashes, merged strip comes out empty, etc..?
Mar 11 '10 #5
In the code above, at the line given below

MergeContextMenuStrip.Items.Add(list[i].Items[j]);
as soon as the item[j] in the list[i] is added to MergeContextMenuStrip this item is deleted from the list[i].items. I dont want this to happen. I just want a copy of this list[i].Items[j] to be pasted in the MergeContextMenuStrip.
Mar 12 '10 #6
GaryTexmo
1,501 Expert 1GB
Hmm, it looks like those ToolStripMenuItems can only belong to one context menu at a time. You're absolutely correct, when you add from one list to the other, it just removes itself. I dug around MSDN and I don't see why this is.

Either way, all you need to do is create a copy of each one you find and then add it to your merged list.

I found a couple of resources on merging context menus. There's a ToolStripManager.Merge method that does this, but it also seems to remove the items from the source and put them in the new location. So I think your best bet, if you want to maintain both lists, is to create a copy.

(Link that might interest you: http://social.msdn.microsoft.com/For...4-3346d0749b00)
Mar 12 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: t_pet422 | last post by:
Hi, I've been scouring the net and reading the PostgreSQL docs for a while now trying to learn how to create a recursive function in PL/pgSQL that will return a whole subtree given a starting...
6
by: sathyashrayan | last post by:
#include<stdio.h> #include<stdlib.h> #include<string.h> struct tree { int data; struct tree *left,*right; }; void init(struct tree *node)
4
by: Andreas Kasparek | last post by:
Hola! I'm preparing my master thesis about a XML Merge Tool implementation and was wondering if there is any open standard for XML diff regarding topics like: - is a diff result computed on...
8
by: sudharsan | last post by:
please gimme the logic to merge two binary search trees?I mean which node has to be the root node of the new binary tree?? Thanks in advance
9
by: anunaygupta | last post by:
Hello all, I have a data structures problem. Assume there are 2 linked lists L1 and L2. They merge into some node. L1 1->2->3->4->5->6 / L2 8->7->9->/ L1 and L2 merge in node with value...
2
by: andrew browning | last post by:
gbd says the segmentation fault is being generated in the insert function. //CONSTRUCTOR tree():data(value_type()), left(0), right(0){}; tree(value_type vt, tree* l = 0, tree* r = 0):...
4
by: whitehatmiracle | last post by:
Hello I have written a program for a binary tree. On compiling one has to first chose option 1 and then delete or search. Im having some trouble with the balancing function. It seems to be going...
0
by: Atos | last post by:
SINGLE-LINKED LIST Let's start with the simplest kind of linked list : the single-linked list which only has one link per node. That node except from the data it contains, which might be...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
4
by: gskbond | last post by:
Below is the node for m way tree class Node { public: Node(int imway); ~Node(); int noofKeys; int *keys; Node **childPointer;
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.