The title pretty much says it all. Can someone explain to me how can I open a context menu by selecting and then right clicking on a ListViewItem
of a ListView
?
I tried using the following code
private void listView1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (listView1.FocusedItem.Bounds.Contains(e.Location) == true)
{
contextMenuStrip1.Show(Cursor.Position);
}
}
}
But I don't know how to register this event handler with the ListView
. Every time I try I get the error that the delegates parameters are wrong because I use MouseEventArgs
instead of EventArgs
.
This is the wrong code I'm using to register the EventHandler
this.listView1.MouseClick += new System.EventHandler(this.listView1_MouseClick);