473,473 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Controlling ContextMenu a bit better.

Hello,

I have a listview control with bunch of entries. When the user
right-clicks on the item, I want a context menu to come up. So I
created a ContextMenu instance and assigned it to ListView.ContextMenu
property.

The problem is that the context menu comes up regardless of whether I
right-click on the item or the empty space or the column header. I want
it only to come up when the user right-clicks on an item. How can I
control the ContextMenu better?
Nov 21 '05 #1
4 3344
Frank Rizzo wrote:
Hello,

I have a listview control with bunch of entries. When the user
right-clicks on the item, I want a context menu to come up. So I
created a ContextMenu instance and assigned it to
ListView.ContextMenu property.

The problem is that the context menu comes up regardless of whether I
right-click on the item or the empty space or the column header. I
want it only to come up when the user right-clicks on an item. How
can I control the ContextMenu better?


Hello Frank:

I think this might work for you:

'************************************************* *******************
Private Sub SelectItem(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles YourListViewName.MouseDown

Dim lvItem As ListViewItem

lvItem = Me.YourListViewName.GetItemAt(e.X, e.Y)
If e.Button = MouseButtons.Right _
AndAlso Not IsNothing(lvItem) Then

Me.YourContextMenu.Show(CType(sender, ListView), _
New Point(e.X, e.Y))

End If

End Sub
'************************************************* ********************

Simon
Nov 21 '05 #2
Hello,

The way I do it is to handle the AfterSelect() event of the listview item
and then determine what has been selected.

If a valid item was selected, then set the ContextMenu property to your
context menu otherwise you can set it to Nothing.

HTH

Regards
Simon Jefferies
mailto:simon[nospam]@cooltoolsonline.co.uk
-- remove [nospam] to email me --
"Frank Rizzo" <no****@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hello,

I have a listview control with bunch of entries. When the user
right-clicks on the item, I want a context menu to come up. So I created
a ContextMenu instance and assigned it to ListView.ContextMenu property.

The problem is that the context menu comes up regardless of whether I
right-click on the item or the empty space or the column header. I want
it only to come up when the user right-clicks on an item. How can I
control the ContextMenu better?

Nov 21 '05 #3
* Frank Rizzo <no****@nospam.com> scripsit:
The problem is that the context menu comes up regardless of whether I
right-click on the item or the empty space or the column header. I
want it only to come up when the user right-clicks on an item. How
can I control the ContextMenu better?


<URL:http://groups.google.de/groups?selm=ujyZAIRcEHA.2840%40TK2MSFTNGP11.phx.gb l>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4
You, my friend, are the man!

Simon Mayr wrote:
Frank Rizzo wrote:
Hello,

I have a listview control with bunch of entries. When the user
right-clicks on the item, I want a context menu to come up. So I
created a ContextMenu instance and assigned it to ListView.ContextMenu
property.

The problem is that the context menu comes up regardless of whether I
right-click on the item or the empty space or the column header. I
want it only to come up when the user right-clicks on an item. How
can I control the ContextMenu better?

Hello Frank:

I think this might work for you:

'************************************************* *******************
Private Sub SelectItem(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles YourListViewName.MouseDown

Dim lvItem As ListViewItem

lvItem = Me.YourListViewName.GetItemAt(e.X, e.Y)
If e.Button = MouseButtons.Right _
AndAlso Not IsNothing(lvItem) Then

Me.YourContextMenu.Show(CType(sender, ListView), _
New Point(e.X, e.Y))

End If

End Sub
'************************************************* ********************

Simon

Nov 21 '05 #5

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

Similar topics

0
by: MD | last post by:
I have a ContextMenu that is assigned to 3 RichTextBox's (i.e., if you right-click on any of the 3 RichTextBox's, you get the same ContextMenu). My ContextMenu has 2 items, each of which have their...
2
by: VR | last post by:
I have a form with a list view control, a button control and a main menu with menuDelete item. Any time I am handling a button click event or menuDelete click event I call DeleteItem() function...
2
by: lukasz | last post by:
I call contextMenu.Show() in OnMouseDown handler the menu shows and then I press mouse button in other area to hide the menu (without selecting an option). Then I receive first OnMouseUp event,...
2
by: Derrick | last post by:
I've been working on an application which has a NotifyIcon (system tray icon), and a corresponding ContextMenu. I want to be able to update this menu dynamically. However, when I make changes to...
0
by: Schorschi | last post by:
Ok the following works... but is ugly and static, need the same idea but dynamic, so as the 'theOwner' form main menu is defined, NotifyIcon.ContextMenu can be updated. Dim the0 As MenuItem =...
7
by: **Developer** | last post by:
I have a usercontrol in which the IDE generated context menu statement is: Friend WithEvents ContextMenuThumbnails As System.Windows.Forms.ContextMenu I want to save the contents of it so I...
11
by: Graham Charles | last post by:
I'm writing a control inheriting from ComboBox, and I'd like to add an entry to the ContextMenu for that combo box. I have no problem if I create an entirely new ContextMenu from scratch, but I'd...
3
by: Libby Sharf | last post by:
Hello, I have several ContextMenus and I want to connect them to the GridControl's ContextMenu property depending on the row that was right clicked. Is there an event that is raised just before...
3
by: asharda | last post by:
Hi, I am trying to create a context menu in my application. The context menu takes menu otems from an XML file. In XAML the code is <Grid.ContextMenu> <ContextMenu Name="cm" StaysOpen="true"...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
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...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.