Solved

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

Posted on 2014-02-04
5
7,838 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Murray Brown
ID: 39835527
I am using built in controls
0
 

Author Comment

by:Murray Brown
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:Murray Brown
ID: 39835727
Thanks
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

626 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