Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8843
  • Last Modified:

VB.net ListView ContextMenuStrip on ListView right click to delete item

Hi

What VB.net code would I use to enable a user to right click on
a ListView item then delete that item

Thanks
0
Murray Brown
Asked:
Murray Brown
  • 3
  • 2
1 Solution
 
CodeCruiserCommented:
For built in controls, you would have to use code to do this

Private Sub listView1_MouseClick(sender As Object, e As MouseEventArgs)
      If e.Button = MouseButtons.Right Then
            If listView1.FocusedItem.Bounds.Contains(e.Location) = True Then
                  contextMenuStrip1.Show(Cursor.Position)
            End If
      End If
End Sub


Are you using those 3rd party controls?
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
I am using built in controls
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
How do I gather the ListView item that I clicked on so that I can delete it
0
 
CodeCruiserCommented:
When you show the contextmenu in MouseClick event, save the X and Y location. Then use HitTest method of listview to find the item where mouse was clicked

http://msdn.microsoft.com/en-us/library/f7548bw9(v=vs.110).aspx
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now