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

Listview and context menu question

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
4 3074
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Richard | last post by:
Hi. I use a ListView to display data in tabular form. Each ListView row corresponds to a data record. The ListView Item of the record is the record key or code. Each SubItem in that row...
0
by: clu82 | last post by:
Is there a way to display a context-sensitive menu after the user has clicked on a listview item and entered into the label edit mode? I can capture the "BeforeLabelEdit" event and display the...
2
by: Brian Keating | last post by:
Hi there, I fear the answer to this question is going to be very simple but it's me running around in circles at the moment. I wish to pop up a context menu on my ListView if and only if I right...
8
by: Sameh Ahmed | last post by:
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....
2
by: Darin | last post by:
I have 2 listview's that have the same context menu tied to them. WHen the user opens the context menu and clicks on one of the menu items, how (within the handles mSelPrice_click) method can I...
1
by: RonNanko | last post by:
I am facing a userinteraction issue with a listview, which is populated/updated by a background task. While the population of the listview is taking place, the user should already be able to...
1
by: =?Utf-8?B?THluYkBtcy5jb20=?= | last post by:
I have a executable winforms application I would like to change. I use quite a number of listview controls in my main form. I dump about 15 columns of data into a couple of listviews. This data...
12
by: Tom Bean | last post by:
I am trying to display a ContextMenuStrip when a user right-clicks on an item in a ListView and have encountered a something that seems strange to me. When the ListView is initially populated,...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.