473,322 Members | 1,846 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,322 software developers and data experts.

Hiding/Closing ContextMenu

Hi,
got a problem with Contextmenu. I got a ListView and want to have the ContextMenu only shown when the user rightclicks an Element
in the Listview. If ther is no element under the mouse cursor no menu shall appear.

The source looks like

private void lstMaterials_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
if(e.Button == MouseButtons.Right){
Point p = new Point(e.X,e.Y);
ListViewItem lv = lstMaterials.GetItemAt(p.X,p.Y);
if(lv!=null){
lv.Selected = true;
conMatMenu.Show(lstMaterials,p);
}
}
}

So far so good, menu only appears when a ListViewItem is below the mouse cursor. But if i right click another Item, the menu just
closes. So i have to click twice on the element (once to close it and once to open the context for the new menu). I failed to find
a way to close an already opened ContextMenu before doing the check if an ListViewItem is below the mousecursor.

Any ideas?

Apr 8 '06 #1
1 9327
A possibility is to use the mousedown event to set the context menu
property of the listview. The standard context menu mechanism will
then kick in, no need to expliclty show the menu

e.g.

private void lstMaterials_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e) {

ListView lvw = (ListView)sender;

if(e.Button == MouseButtons.Right){

ListViewItem lv = lstMaterials.GetItemAt(e.X,e.Y);
if(lv!=null){
lv.Selected = true;
lvw.ContextMenu = conMatMenu;
else {
lvw.ContextMenu = nothing;
}
}
}
hth,
Alan.

Apr 8 '06 #2

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

Similar topics

2
by: Gustavo Franco | last post by:
Hi, Basic Question, difficult answer 1) Thread one; Open Context Menu.
2
by: Zieben | last post by:
Hello! I have such problem! I have my UserControl. I override property ContextMenu for this Control as ..... new ContextMenu ContextMenu{ set {_contextMenu = value;}
3
by: VMI | last post by:
How difficult is it to hide my program in the system tray? It's not something that's required, but it'd look to add it since the program will be writing an ascii file every minute. And it wouldn't...
5
by: Ivan | last post by:
I am used to VB6 and am not sure how to do this in Vstudio .NET. I have a main form which calls other forms. I want to disable that main form while other ones are called. I tried hiding it and...
4
by: Fred | last post by:
Hi, I have a list box with a context menu. When I right click the menu appears as expected. However when I select an option on the context menu the menu does not close. The click event on the...
0
by: Marcel Brekelmans | last post by:
Hi, I use contextmenu's in my application. For each menu-item I display a little text in the StatusBar, using the Select event for each menu-item. I would like to clear the StatusBar as soon...
11
by: Alex | last post by:
Hello all, I have a main form(say "form1") .i want to display another form(say "form2") on occuring of an event (say a button click) and want to hide it after some time so that it will again...
1
by: sugee | last post by:
hi, To display the shortcut menu, i have used ContextMenu.Show() method.After an item on the ContextMenu is selected and clicked, the ContextMenu, generally, should be hidden. It will happen...
12
by: kronecker | last post by:
I found this nifty routine that closes a form one by one every time it is called. However, I need to hide them instead of closing them. Is there a way to alter the code? I assume it has something...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...

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.