By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,609 Members | 3,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,609 IT Pros & Developers. It's quick & easy.

MDI MenuItem Popup event - can't use MenuItems.Add

P: n/a
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.
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

Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.