473,382 Members | 1,726 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,382 software developers and data experts.

CloneMenu

Hi, all!

Right to the topic:

In the main menu of the form I have View->Image-and then 4 submenu
items (let's call them original submenu). I want the same submenu as a
Context menu. To do this I use such construct:

foreach (MenuItem mi in this.menuImage.MenuItems)
{
mi.Enabled = imageLoaded;
ctxtMenuView.MenuItems.Add(mi.Index, mi.CloneMenu());
}

All is kosher because CloneMenu does a deep copy.

In fact I create new items (by cloning). So if attributes of the
original submenu somehow are changed after cloned, too bad: changes are
not reflected on context menu.

To solve such "hypothetical" problem, I modified the line:
ctxtMenuView.MenuItems.Add(mi.Index, mi);

I understood that both MenuItems collection (original submenu and
context menu) are referencing the same MenuItem objects.

The result is disappointing. Addition of the MenuItem mi to the context
menu MenuItems collection REMOVES IT(!???) from the original submenu
MenuItems collection.

Why? Is it by design or I'm doing something wrong?

NB. The situation seams hypothetical, but with the spread of multi core
processors may hurt somebody.

Nov 3 '06 #1
2 1791
Lev,

If you do a deep copy it certainly will not go, most copies with dotNet (the
exceptions I know direct from mind are the copyTo, copying a serialized
object or those in Adonet) are shallow copies and that is in my idea what
you need. Only the references need to be copied.

Just my idea of your problem,

Cor

"Lev Elbert" <el*******@hotmail.comschreef in bericht
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi, all!

Right to the topic:

In the main menu of the form I have View->Image-and then 4 submenu
items (let's call them original submenu). I want the same submenu as a
Context menu. To do this I use such construct:

foreach (MenuItem mi in this.menuImage.MenuItems)
{
mi.Enabled = imageLoaded;
ctxtMenuView.MenuItems.Add(mi.Index, mi.CloneMenu());
}

All is kosher because CloneMenu does a deep copy.

In fact I create new items (by cloning). So if attributes of the
original submenu somehow are changed after cloned, too bad: changes are
not reflected on context menu.

To solve such "hypothetical" problem, I modified the line:
ctxtMenuView.MenuItems.Add(mi.Index, mi);

I understood that both MenuItems collection (original submenu and
context menu) are referencing the same MenuItem objects.

The result is disappointing. Addition of the MenuItem mi to the context
menu MenuItems collection REMOVES IT(!???) from the original submenu
MenuItems collection.

Why? Is it by design or I'm doing something wrong?

NB. The situation seams hypothetical, but with the spread of multi core
processors may hurt somebody.

Nov 3 '06 #2
Lev Elbert wrote:
Hi, all!

Right to the topic:

In the main menu of the form I have View->Image-and then 4 submenu
items (let's call them original submenu). I want the same submenu as a
Context menu. To do this I use such construct:

foreach (MenuItem mi in this.menuImage.MenuItems)
{
mi.Enabled = imageLoaded;
ctxtMenuView.MenuItems.Add(mi.Index, mi.CloneMenu());
}

All is kosher because CloneMenu does a deep copy.

In fact I create new items (by cloning). So if attributes of the
original submenu somehow are changed after cloned, too bad: changes are
not reflected on context menu.

To solve such "hypothetical" problem, I modified the line:
ctxtMenuView.MenuItems.Add(mi.Index, mi);

I understood that both MenuItems collection (original submenu and
context menu) are referencing the same MenuItem objects.

The result is disappointing. Addition of the MenuItem mi to the context
menu MenuItems collection REMOVES IT(!???) from the original submenu
MenuItems collection.

Why? Is it by design or I'm doing something wrong?

NB. The situation seams hypothetical, but with the spread of multi core
processors may hurt somebody.
Hi,

Yes! It's by design. However, to solve such a problem, you'd pass in
your 'this.menuImage' reference /as/ the context menu - you don't need to
do any copying.

--
Hope this helps,
Tom Spink

Google first, ask later.
Nov 4 '06 #3

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

Similar topics

2
by: VR | last post by:
I have a form with a list view control, a button control and a main menu with menuDelete item. Any time I am handling a button click event or menuDelete click event I call DeleteItem() function...
4
by: M | last post by:
Hopefully this will come out right but this is what I'd like Shapes ======= Squares |___by color |___Red |___Yellow |___by size |__Large
1
by: MrNobody | last post by:
For the the sake of keeping my code simple, I wanted a ContextMenu and a MainMenu to share some MenuItems, but it turns out when I Add() one MenuItem to the other it 'steals' that MenuItem so it...
0
by: Neo | last post by:
These are not working in Visual Studio .NET 2005 beta 1 (no such methods)mainMenu1.MergeMenu(contextMenu1);andmyContextMenu.MenuItems.Add(fileMenuItem.CloneMenu());Are these being changed from...
2
by: Neo | last post by:
Sorry for reposting, subject line was incorrect... These are not working in Visual Studio .NET 2005 beta 1 (no such methods) mainMenu1.MergeMenu(contextMenu1); and
1
by: I_AM_DON_AND_YOU? | last post by:
I have a contextmenu1 many many menus options and then each options have many sub-levels and this thing goes on. .... I wanted to copy all this to MainMenu1.... Is it possible? I want to copy this...
2
by: Brano | last post by:
Hi all, I have this problem I have a menu structure in my VB.NET application that is about 4 levels deep. I need an CTRL+key access to the 3rd level so that if user press CTRL+key the 3rd menu...
7
by: **Developer** | last post by:
I have a usercontrol in which the IDE generated context menu statement is: Friend WithEvents ContextMenuThumbnails As System.Windows.Forms.ContextMenu I want to save the contents of it so I...
2
by: polocar | last post by:
Hi, I'm writing a program using Visual C# 2005 Professional Edition, and I was trying to assign multiple MainMenu objects (one by one, of course) to the same Form (let's suppose 2 MainMenu...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.