Solved

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

Posted on 2014-02-04
5
7,458 Views
Last Modified: 2014-02-05
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
Comment
Question by:murbro
  • 3
  • 2
5 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39835499
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
 

Author Comment

by:murbro
ID: 39835527
I am using built in controls
0
 

Author Comment

by:murbro
ID: 39835558
How do I gather the ListView item that I clicked on so that I can delete it
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39835673
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
 

Author Closing Comment

by:murbro
ID: 39835727
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question