473,398 Members | 2,380 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,398 software developers and data experts.

Building context menus after MouseDown

I have a list view which contains various object types and I need to
create a context menu with menu items dependent on the object type. I
can detect the object type at MouseDown. I've written code to create
the context menu but on first click, it doesn't work. On the second
click on the same type of object, it shows the correct menu items.
After that, basically, it shows the menu items that correspond to the
previous object I clicked on.

Has anyone seen this before? I've posted a subset of the code below -
I know it's not particularly nice but, for now, I'm only interested in
fixing it, not rewriting it as I'm rewriting the whole thing from the
ground up with proper Unit Tests soon.

SSG

private void lstvwAD_MouseDown(object sender, MouseEventArgs e)
{
cmnuDomain.MenuItems.Clear();
cmnuDomain.MenuItems.AddRange(new MenuItem[] {
cmnuDomainLargeIcons,
cmnuDomainSmallIcons,
cmnuDomainDetails,
cmnuDomainList});
int nextMenuItemIndex = 4;

if (lstvwAD.SelectedItems.Count == 1)
{
switch
(((DirectoryEntry)lstvwAD.SelectedItems[0].Tag).SchemaClassName)
{
case "computer":
MenuItem cmnuDomainSeparator = new MenuItem("-");
this.cmnuDomain.MenuItems.Add(cmnuDomainSeparator) ;
cmnuDomainSeparator.Index = nextMenuItemIndex++;
this.cmnuDomain.MenuItems.Add(cmnuDomainViewEPOAvt ivity);
cmnuDomainViewEPOAvtivity.Index = nextMenuItemIndex++;
break;
case "user":
MenuItem cmnuDomainSeparator = new MenuItem("-");
this.cmnuDomain.MenuItems.Add(cmnuDomainSeparator) ;
cmnuDomainSeparator.Index = nextMenuItemIndex++;
this.cmnuDomain.MenuItems.Add(cmnuDomainProperties WRBR);
cmnuDomainPropertiesWRBR.Index = nextMenuItemIndex++;
this.cmnuDomain.MenuItems.Add(cmnuDomainMoveAndDis able);
cmnuDomainMoveAndDisable.Index = nextMenuItemIndex++;
break;
}
}
this.lstvwAD.ContextMenu = this.cmnuDomain;

Mar 23 '06 #1
0 1029

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
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...
0
by: allen | last post by:
If I create a control library control (and change the base control from usercontrol to control). Add that control to the toolbox, then add that control to a windows form. Then add a context menu...
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...
0
by: Dino M. Buljubasic | last post by:
I have several context menu added to my forms. The forms are displaying items in a list view. When I click on an item in a list view, a popup context menu shows allowing me to chese between...
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...
1
by: Rory | last post by:
Hi - I've seen quite a few posts that almost match this but haven't found a solution that works. I have an explorer-like application with a treeview in the lefthand pane. When I right-click on a...
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...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.