Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 597117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:14:43+00:00 2026-05-13T16:14:43+00:00

I am getting some erratic behavior from a ContextMenuStip : private void lstModules_MouseMove(object sender

  • 0

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;
 }
  1. 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.
  2. If a context menu is visible, and an item is selected, the item details do not change.
  3. 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:14:44+00:00Added an answer on May 13, 2026 at 4:14 pm

    I tried to reproduce your problem as far as I could. I think I can help you out with at least two of the three issues you’ve listed.

    1. The item in the list view is not always properly selected. In other words, when the item is selected, a detail string value is displayed in a label control.

    You can be notified when an item has been selected via the ListView.ItemSelectionChanged event:

    //
    // this handler's only responsibility is updating the item info label:
    //
    void lstModules_ItemSelectionChanged(object sender,
                                         ListViewItemSelectionChangedEventArgs e)
    {
        if (e.IsSelected)
        {
            // an item has been selected; update the label, e.g.:
            lblModuleDetails.Text = e.Item.Text;
        }
        else
        {
            // some item has been de-selected; clear the label:
            lblModuleDetails.Text = string.Empty;
        }
    }
    

    3. Context menu location briefly appears at the old mouse location then moves to the new mouse location.

    I believe you try to do too much. Let the framework handle the displaying of the context menu which you have specified via the ListView.ContextMenuStrip property. The effect you experience is caused by your manually calling ContextMenuStrip.Show(...), which results in the displaying of the context menu by the framework, and then you doing the same thing a second time, at another location.

    Therefore, try not to call this function; the context menu should still appear.

    //
    // this handler's 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 that works, you can also get rid of your lstModules_MouseMove event handler and the mouse location object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting some inexplicable behavior from easymock and a JUnit test case. I'm receiving
Getting some odd behavior from google custom search that I can't seem to suss
I'm getting some strange behaviour from EF Code First when I add an object
Getting some object from the layout file (say, test.xml) requiring setting this layout in
I am getting erratic behavior from Eclipse ( 3.7.0 ) all of the sudden...
I'm getting some strange behavior using COS() and SIN() libraries in Fortran 77. It
Getting some zlib error in the middle of cloning big (4 GB) repo from
I am getting some data from an xml that updates every 2 minutes or
I am getting some HTML from server and showing in Textview. The HTML have
I'm getting some weird behaviour from a for loop that reads each line in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.