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

Listview and context menu question

P: n/a
Hello there
i have a context menu linmked to a listview control.
I want the context mnu to appear ONLY when i right click on an item and not
any place in listview.
any ideas?
Thanks in advance.
PS: i want the same with treeviews
Regards
Sameh
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I do it by checking the selecteditems.count property of the listview.. but I
am sure there are better ways of doing it

if selecteditems.count > 0
' show menu
end if

or if you have multi select on and want right click on only one selected

if selected items.count = 1
' show menu
end if

just an idea
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:Oy**************@TK2MSFTNGP12.phx.gbl...
Hello there
i have a context menu linmked to a listview control.
I want the context mnu to appear ONLY when i right click on an item and not any place in listview.
any ideas?
Thanks in advance.
PS: i want the same with treeviews
Regards
Sameh

Nov 20 '05 #2

P: n/a
Thanks for ur time
this is what i use
but the context menu appears even if u right click on a different item
i don't want it to appear when u select an item then move in an empty space
"Brian Henry" <brian.henry[nospam]@adelphia.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I do it by checking the selecteditems.count property of the listview.. but I am sure there are better ways of doing it

if selecteditems.count > 0
' show menu
end if

or if you have multi select on and want right click on only one selected

if selected items.count = 1
' show menu
end if

just an idea
"Sameh Ahmed" <es******@hotmail.com> wrote in message
news:Oy**************@TK2MSFTNGP12.phx.gbl...
Hello there
i have a context menu linmked to a listview control.
I want the context mnu to appear ONLY when i right click on an item and

not
any place in listview.
any ideas?
Thanks in advance.
PS: i want the same with treeviews
Regards
Sameh


Nov 20 '05 #3

P: n/a
Sameh,

You can include an If ....Else statement to check whether there is any
selected item in your list view. If no item is selected, then set the
visible property of your context menu item(s) to false.

Carmen

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #4

P: n/a
example:

Private Sub ListView1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ListView1.SelectedIndexChanged
ControlContextMnu()
End Sub

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
ControlContextMnu()
End Sub

Private Sub ControlContextMnu()
Dim ctmtem As MenuItem
If Me.ListView1.SelectedItems.Count = 0 Then
For Each mnuitem In ContextMenu1.MenuItems
mnuitem.Visible = False
Next
Else
For Each mnuitem In ContextMenu1.MenuItems
mnuitem.Visible = True
Next
End If
End Sub

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.