Solved

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

Posted on 2014-02-04
5
6,985 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

864 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now