MergeMenu method modifies the source and the target MenuItem objects in Visual Studio .NET (834613)



The information in this article applies to:

  • Microsoft Visual Basic .NET (2003)
  • Microsoft Visual Basic .NET (2002)

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 "More Information" 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.

MORE INFORMATION

Steps to reproduce the problem

  1. Start Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. In the New Project dialog box, click Windows Application.

    You can select either Visual C# Projects or Visual Basic Projects.
  4. Add a MainMenu control from the toolbox to the Form1 form.
  5. Add a MenuItem that is named A and a MenuItem that is named B to the MainMenu control.
  6. Add another MenuItem that is named A1 under A. Add another MenuItem that is named B1 under B.
  7. Add a button to the Form1 form.
  8. 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)
  9. On the Debug menu, click Start.
  10. 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.

REFERENCES

For additional information about the MenuItem.MergeMenu method, visit the following Microsoft Developer Network (MSDN) Web site:

Modification Type:MinorLast Reviewed:2/9/2006
Keywords:kbvs2005swept kbvs2005doesnotapply kbMenu kbControl kbprb KB834613 kbAudDeveloper