I am wanting to popup a menu when a user presses the right mouse button on my listview.
Here is my code:
If e.Button = MouseButtons.Right Then
Me.cnmnuLstCopy.Show(Me.cnmnuLstCopy, e.Location)
End If
I am getting this error:
An unhandled exception of type ‘System.StackOverflowException’ occurred in System.Windows.Forms.dll
Why would this be happening?
It’s happening because that code is trying to show the menu on the menu, not on the listview. The correct code is
You can actually pop up a context menu without any code. Simply add a context menu strip to your form and then on your listview, set the ContextMenuStrip property. No code required and it works like you’d expect.