I'm trying to add menu items dynamically in the Popup event of a MenuItem in
an MDI child form. Actually, I'm using the Genghis MRU class, but have also
dumbed it down to a simple test case in a standard WinForms app.
When trying to call mnuItemFoo.MenuItems.Add( "some text" ) in the Popup
handler, I get a null reference exception.
System.NullReferenceException
Object reference not sent to an instance of an object.
It's weird - the call to MenuItems.Add is successfull. Only when I leave
the Popup handler, do I get the exception, thrown from deep in the callstack
at MenuItem.UpdateMenuItemIfDirty( ) ???
My form is an MDI child, and the menu I'm trying to add to is a merged menu
(i.e. "File" menu) with the MDI container.
Anybody else run into this? Is there a work around?
The only thing I can get to work is to dynamically add the menu items
somewhere else, other than the Popup event. (e.g. when a "document" is
opened, add the MenuItem right then, not later when the user clicks the
menu)