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.