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

Dynamic Context Menus

P: n/a
Hi,

A project I am working on has a requirement for dynamic
menus. For the most part this works really well.

The menus I'm creating a based on files and directories,
so naturally the menu creation takes some time.

The approach I took was to override the OnSelect method
of the MenuItem class, which had code to populate the
child items.

This worked really well until I had to use the menu as a
context menu.. I found that the context menu does not
refresh properly below the first level menu..

The only way I can get this to work correctly is to use
reflection to call the private UpdateMenuItem method on
the MenuItem class.

Has anybody else had experiance with this??

Is the fact that the MenuItem does not refresh correctly
when in a context menu a bug???

Any feedback would be great..

Cheers
Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I just took a look at that and it does appear to be a serious BUG.
A workaround, other than your own, is to set the forms ContextMenu property
to the context menu in question. Of course this is not the ideal situation
as your context menu will now popup from every control that does not have
it's own context menu.

As for that slow menu generation, are you adding the MenuItems to your
ContextMenu in a loop? If so, a faster way is to create a MenuItem Array and
set each member of the array to a new menuitem from within the loop. Then
outside the loop use AddRange to add all the menu items at once.

"Eddie de Bear" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
Hi,

A project I am working on has a requirement for dynamic
menus. For the most part this works really well.

The menus I'm creating a based on files and directories,
so naturally the menu creation takes some time.

The approach I took was to override the OnSelect method
of the MenuItem class, which had code to populate the
child items.

This worked really well until I had to use the menu as a
context menu.. I found that the context menu does not
refresh properly below the first level menu..

The only way I can get this to work correctly is to use
reflection to call the private UpdateMenuItem method on
the MenuItem class.

Has anybody else had experiance with this??

Is the fact that the MenuItem does not refresh correctly
when in a context menu a bug???

Any feedback would be great..

Cheers

Jul 21 '05 #2

P: n/a
The reason me menu creation is slow is because the menu
is based on existance of files in the OS as well as
security settings in the database... This retrieval takes
time.. Not the actual menuitem creation itself..

I was actually hoping some of the MS guys could possibly
take a look at this problem, becuase I have spent several
days on this, and have come to the conclusion that it is
a bug...

-----Original Message-----
I just took a look at that and it does appear to be a serious BUG.A workaround, other than your own, is to set the forms ContextMenu propertyto the context menu in question. Of course this is not the ideal situationas your context menu will now popup from every control that does not haveit's own context menu.

As for that slow menu generation, are you adding the MenuItems to yourContextMenu in a loop? If so, a faster way is to create a MenuItem Array andset each member of the array to a new menuitem from within the loop. Thenoutside the loop use AddRange to add all the menu items at once.
"Eddie de Bear" <an*******@discussions.microsoft.com> wrote in messagenews:07****************************@phx.gbl...
Hi,

A project I am working on has a requirement for dynamic
menus. For the most part this works really well.

The menus I'm creating a based on files and directories, so naturally the menu creation takes some time.

The approach I took was to override the OnSelect method
of the MenuItem class, which had code to populate the
child items.

This worked really well until I had to use the menu as a context menu.. I found that the context menu does not
refresh properly below the first level menu..

The only way I can get this to work correctly is to use
reflection to call the private UpdateMenuItem method on
the MenuItem class.

Has anybody else had experiance with this??

Is the fact that the MenuItem does not refresh correctly when in a context menu a bug???

Any feedback would be great..

Cheers

.

Jul 21 '05 #3

P: n/a
Well this was really bugging me and I just couldn't let it go.
After many unsuccessful overcomplicated attempts I finally came up with a
very simple solution.

Remove the MenuItem that you wish to add items to, add the items then re-add
the Menuitem to the ContextMenu.

VB.Net Example

Dim DynamicParentIndex As Integer = DynamicParent.Index
MyContextMenu.MenuItems.Remove(DynamicParent)
DynamicParent.MenuItems.Clear 'Optional
DynamicParent.MenuItems.AddRange(DynamicMenuItemsA rray)
MyContextMenu.MenuItems.Add(DynamicParentIndex, DynamicParent)
"Eddie de Bear" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
Hi,

A project I am working on has a requirement for dynamic
menus. For the most part this works really well.

The menus I'm creating a based on files and directories,
so naturally the menu creation takes some time.

The approach I took was to override the OnSelect method
of the MenuItem class, which had code to populate the
child items.

This worked really well until I had to use the menu as a
context menu.. I found that the context menu does not
refresh properly below the first level menu..

The only way I can get this to work correctly is to use
reflection to call the private UpdateMenuItem method on
the MenuItem class.

Has anybody else had experiance with this??

Is the fact that the MenuItem does not refresh correctly
when in a context menu a bug???

Any feedback would be great..

Cheers

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.