Microsoft KB Archive/834613

= MergeMenu method modifies the source and the target MenuItem objects in Visual Studio .NET =

Article ID: 834613

Article Last Modified on 5/17/2007

-

APPLIES TO


 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition

-





SYMPTOMS
The MergeMenu method of the MenuItem object modifies both the source MenuItem objects and the target MenuItem objects. The result is that the same items are in both the source MenuItem objects and the target MenuItem objects.



RESOLUTION
To resolve this problem, replace the code in step 8 of the &quot;More Information&quot; section with the following code:

Microsoft Visual C# .NET menuItem1.MergeMenu(menuItem2.CloneMenu); Microsoft Visual Basic .NET MenuItem1.MergeMenu(MenuItem2.CloneMenu)



STATUS
This behavior is by design.



Steps to reproduce the problem
 Start Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project. In the New Project dialog box, click Windows Application.

You can select either Visual C# Projects or Visual Basic Projects. Add a MainMenu control from the toolbox to the Form1 form. Add a MenuItem that is named A and a MenuItem that is named B to the MainMenu control. Add another MenuItem that is named A1 under A. Add another MenuItem that is named B1 under B.</li> Add a button to the Form1 form.</li>  Add the following code to the OnClick event handler of the Button1 button:

Visual C# .NET menuItem1.MergeMenu(menuItem2); Visual Basic .NET MenuItem1.MergeMenu(MenuItem2) </li> On the Debug menu, click Start.</li> On the Form1 form, click the Button1 button.

Notice that the B1 MenuItem object is added to the A MenuItem object and that the A1 MenuItem object is added to the B MenuItem object.</li></ol>

<div class="references_section">