473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dynamic Context Menus

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
3 4722
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Patryk | last post by:
Hi I'm making a web application which is a copy of existing desktop application. I use telerik controlls for MS visual studio I have a little bit complicated situation beacuse I need context...
1
by: Doug Bell | last post by:
Hi, If I modify my Registry adding a new key HKEY_CLASSES_ROOT\*\shell\Use My App\command with a (Default) Value of C:\Program Files\Doug\DotNetApps\MyApp.exe "%1" then right clicking on files in...
4
by: ssg31415926 | last post by:
I've got a ListView which can show many different types of object. I need to display a ContextMenu whose MenuItems depend on the object type. I was planning to pre-create the ContextMenus when...
2
by: Dino M. Buljubasic | last post by:
I have several context menus added to my form. The form is displaying items in listviews connected to the context menus. When I click on an item in a list view, a popup context menu shows allowing...
3
by: Eddie de Bear | last post by:
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...
3
by: RahimAsif | last post by:
I am writing an application that requires the a portion of the main menu to be dynamic. The menu has file, panels, view files and help across the top. The view files sub menu needs to be...
2
by: Ron M. Newman | last post by:
Hi, Just need a little advice. Id like to build *dynamic* context menus for tree nodes. I'm pretty versed in building context menus and attaching them to tree nodes. My question is, what...
4
by: Karl | last post by:
Hi all, I want to write an application that is launched from the context menu in Windows Explorer/Computer. That is to say, when I am browsing around my hard drive and get to any location I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.