I use Window Form C# My code
private void ViewList_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Point pt = ViewList.PointToScreen(e.Location);
ListViewItem item = ViewList.GetItemAt(pt.X, pt.Y);
if (item != null)
{
contextMenuStrip1.Enabled = true;
contextMenuStrip1.Show(pt);
}
//else { }
}
}
But it not working sometimes.开发者_开发问答 How to have a contentmenu for listview and listviewitem?
if(e.Buttons == MouseButton.Right)
contextMenuStrip1.Show(e.X+val1, e.Y+val2);
val1 and val2 are integers values, if menu doesn't come to the right position you can add some values in it to make it on the right position :)
listView1.ContextMenu = yourcontextmenu;
or you can set it from properties window also
精彩评论