468,283 Members | 1,845 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,283 developers. It's quick & easy.

Context Menu question

J L
I have a form with a listview on it and a context menu. I handle the
right click event on the listview but after handling the event, the
context menu then appears. I would like to disable it if the user
right clicks on an item in the listview. I do like it to appear if the
user right clicks on an empty part of the listview.

Can this be done? If so how?

TIA
John
Nov 21 '05 #1
3 880
Hi J L,

In mousedown event of the listview:

Dim blnState As Boolean = (e.Button = MouseButtons.Right) AndAlso
(ListView1.SelectedItems.Count > 0)

mnuAdd.Visible = blnstate

mnuRemove.Visible = blnstate
"J L" <jo**@marymonte.com> wrote in message
news:em********************************@4ax.com...
I have a form with a listview on it and a context menu. I handle the
right click event on the listview but after handling the event, the
context menu then appears. I would like to disable it if the user
right clicks on an item in the listview. I do like it to appear if the
user right clicks on an empty part of the listview.

Can this be done? If so how?

TIA
John

Nov 21 '05 #2
"J L" <jo**@marymonte.com> schrieb:
I have a form with a listview on it and a context menu. I handle the
right click event on the listview but after handling the event, the
context menu then appears. I would like to disable it if the user
right clicks on an item in the listview. I do like it to appear if the
user right clicks on an empty part of the listview.


\\\
Private Sub ListView1_MouseUp( _
ByVal sender As Object, _
ByVal e As MouseEventArgs _
) Handles ListView1.MouseUp
Dim i As ListViewItem = Me.ListView1.GetItemAt(e.X, e.Y)
If i Is Nothing Then
Me.ContextMenu1.Show(...)
End If
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #3
J L
Thank you both. Exactly what I needed.

John

On Tue, 31 May 2005 11:13:52 +0200, "Herfried K. Wagner [MVP]"
<hi***************@gmx.at> wrote:
"J L" <jo**@marymonte.com> schrieb:
I have a form with a listview on it and a context menu. I handle the
right click event on the listview but after handling the event, the
context menu then appears. I would like to disable it if the user
right clicks on an item in the listview. I do like it to appear if the
user right clicks on an empty part of the listview.


\\\
Private Sub ListView1_MouseUp( _
ByVal sender As Object, _
ByVal e As MouseEventArgs _
) Handles ListView1.MouseUp
Dim i As ListViewItem = Me.ListView1.GetItemAt(e.X, e.Y)
If i Is Nothing Then
Me.ContextMenu1.Show(...)
End If
End Sub
///


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Eddie de Bear | last post: by
2 posts views Thread by Gustavo Franco | last post: by
4 posts views Thread by Mohit Gupta | last post: by
4 posts views Thread by Aaron Queenan | last post: by
8 posts views Thread by Dennis C. Drumm | last post: by
13 posts views Thread by Steven Smith | last post: by
5 posts views Thread by yxq | last post: by
1 post views Thread by Chris Murphy via DotNetMonster.com | last post: by
2 posts views Thread by Ron M. Newman | last post: by
reply views Thread by NPC403 | last post: by
2 posts views Thread by MrBee | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.