I am getting some erratic behavior from a ContextMenuStip
:
private void lstModules_MouseMove(object sender , MouseEventArgs e)
{ mouse = e.Location; }
private void lstModules_MouseDown(object sender , MouseEventArgs e)
{
ListViewItem item = null;
if((hitTest = lstModules.HitTest(mouse)) != null)
item = hitTest.Item;
switch (e.Button)
{
case MouseButtons.Right:
if (item != null)
{
// valid item selection
ShowModuleDetails(item.Name);
lstModules.ContextMenuStrip = mnuContext_Module;
}
else
{
// right-click - no item selection
lblModuleDetails.Text = string.Empty;
lstModules.ContextMenuStrip = mnuContext_Desktop;
}
lstModules.ContextMenuStrip.Show(lstModules , mouse);
break;
case MouseButtons.Left:
if (item != null)
{ ShowModuleDetails(item.Name); }
break;
}
}
private void ShowModuleDetails(string modName)
{
// get module details from dictionary
lblModuleDetails.Text = Modules[modName].Details;
}
- The item in the list view is not properly selected when the context menu is showing. In other words, when the item is selected, a detail string value is displayed in a label control.
- If a context menu is visible, and an item is selected, the item details do not change.
- Context menu location briefly appears at the old mouse location then moves to the new mouse location.
Is there something I'm doing wrong with the context menus?