Listview and context menu question by:Sameh Ahmed
|
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
|
| | Reply: by:Brian Henry
|
| | 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
|
| | Reply: by:Sameh Ahmed
|
| | 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
|
| | Reply: by:sawhar@hotmail-dot-com.no-spam.invalid (carmen)
|
| | 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
|
| | Reply: by:sawhar@hotmail-dot-com.no-spam.invalid (carmen)
|
| | 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
|
0 Comments:
Post a Comment
<< Home