Adding to an existing MenuItem's MenuItem Collection Dynamically

S

snesbit

I have a static ContextMenu already built and it works.

I am trying to add a submenu (right arrow with a new menuitem list) dynamically when the popup is created.

The new set of menuitems requires some DB queries to be done and then the menuitems to be added to the Menuitems collection of an existing menuitem

This operation is sensitive to the record that the user has right clicked, so this dynamic sublist of actions can be different each time the user right clicks.


However while I get the context menu every time the user right clicks, the dynamically generated submenu only displays once per execution of the application.

Someone must have done this before.....Please Help.....Frustrated..

I have tried to clear the menuitems for the dynamic menuitems collection on the dispose of the popup event, but dispose is not called and there is not an event that tells me when this menu is no longer displayed.

argghhkd#&#&#&#
 
M

Mick Doherty

Either assign the contextmenu to the control from which you are popping it
up, instead of calling ContextMenu.Show(), or remove the parent item from
the contextmenu, modify it's child menuitems and then add the parent item
back to the context menu.
 
S

snesbit

Interesting....

First I tried the contextmenu assignment, however since I'm working with a
grid and my submenu is sensitive to the row the user has right clicked on,
this method does not work. What happens is that the grid does not display
the menu the first time. It seems that when the context menu is directly
assigne to the grid, the grid wants to do its thing before letting the
context menu do its thing.

Next I removed the parent menuitem as suggested. Changed the submenus and
then reattached the parent at the correct index. This is more lines of code
and while intuitive, have a very manual feel. But it WORKS!

I'm not sure if the 2005 Visual Studio control will act the same, but I'll
have to try it... (We are testing for future releases)

Thanks for the help... At least I have a design pattern that works today.
Now for the mundane recoding effort.



"Mick Doherty"
 
J

Jeffrey Tan[MSFT]

Hi snesbit,

I find that this issue has already been posted in
"microsoft.public.dotnet.framework.windowsforms.controls" newsgroup. I have
added a reply to you in that newsgroup. You may follow up there and I will
monitor that thread. Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top