Microsoft KB Archive/328589

= BUG: Select Event in MenuItem Class Does Not Fire After Adding a Submenu at Runtime =

Article ID: 328589

Article Last Modified on 2/12/2003

-

APPLIES TO


 * Microsoft .NET Framework 1.0 Service Pack 2

-



This article was previously published under Q328589



SYMPTOMS
If you add a submenu at runtime, the Select event in the MenuItem class does not fire the first time that you move the pointer over the command.



CAUSE
When a submenu is added, handles for the items that were already in the MenuItem collection are discarded.



RESOLUTION
To resolve the issue, get a reference to the handle of MenuItem. This will forcibly re-create the handle for the MenuItem. The following sample code demonstrates how to do this.

Visual Basic .NET
Dim NewMenu As MenuItem NewMenu = mnuViews.MenuItems.Add(&quot;TestMenu&quot;) 'Immediately after adding the menu item, add the following statement: Dim handle As IntPtr = mnuViews.Handle

C#
MenuItem nMenu = new MenuItem(&quot;TestMenu&quot;); mnuViews.MenuItems.Add(nMenu); //Immediately after adding the menu item, add the following statement: IntPtr handle = mnuViews.Handle;



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

Keywords: kbbug kbnetframe100presp3fix kbpending KB328589

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.