I tried to reproduce your problem as much as I could. I think I can help you with at least two of the three problems you listed.
1. The list item is not always correctly selected. In other words, when an item is selected, the string value of the part is displayed in the label control.
You can receive notifications when an item has been selected using the ListView.ItemSelectionChanged event:
3. The location of the context menu is briefly displayed in the old mouse folder, and then moves to the new location of the mouse.
I believe you are trying to do too much. Let the structure handle the context menu display that you specified using the ListView.ContextMenuStrip property. The effect that you experience is caused by your manual call to ContextMenuStrip.Show(...) , which causes the context menu to be displayed using the framework, and then you do the same a second time in another place.
Therefore, try not to call this function; a context menu should appear.
// // this handler only responsibility is setting the correct context menu: // void lstModules_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { var hitTest = lstModules.HitTest(e.Location); if (hitTest != null && hitTest.Item != null) { lstModules.ContextMenuStrip = mnuContext_Module; } else { lstModules.ContextMenuStrip = mnuContext_Desktop; } } }
Btw. If this works, you can also get rid of the lstModules_MouseMove event lstModules_MouseMove and the mouse location object.
stakx source share