By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,435 Members | 2,033 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,435 IT Pros & Developers. It's quick & easy.

Context Menu question

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
"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

P: n/a
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.