Resolved MouseDoubleClick not firing until I click a third time somewhere else

tim8w

Well-known member
Joined
Sep 8, 2020
Messages
131
Programming Experience
10+
Hi,
I have a standard ListBox where I am trying to implement the MouseDoubleClick event. The event doesn't fire until I have DoubleClicked and then click either on another item or empty space. (Clicking on another item selects the other item, of course). I am also implementing the following events:

DragDrop
DragEnter
DragOver
MouseMove
MouseUp
SelectedIndexChanged

Could having any of these other events enabled be causing the behavior I am observing?

Thanks,
Tim
 
Could having any of these other events enabled be causing the behavior I am observing?
What did you find out when you tested for yourself? You can do that. You can create a new test project and test just the MouseDoubleClick event and see whether it behaves as you expect. If it does, you can then start adding more functionality until it breaks and then you know where the issue lies. Even if you can't work out what to do about it, at least you can provide us with all the relevant information. That's how software development works.
 
Test program worked just fine.

MouseUp, MouseDoubleClick, MouseUp

In my original program, I don't get any event, not even one MouseUp and then when I click on an item or empty space I only get MouseDoubleClick
 
By any chance in your actual program you have committed the cardinal sin of using Applicaition.DoEvents()? If so see the big read caution box in the documentation.
 
In any of your other mouse event handlers, are you bring up a dialog or message box? Those will effectively have the same effect as Application.DoEvents() where a new message pump is running.

Anyway, I would still encourage you to @jmcilhinney 's advise to come up with a minimal reproduction case. Start of with an empty app and add just enough stuff in it to reproduce the problem.
 
Maybe. In MouseUp, if the RightMouseButton is clicked, I bring up a ContextMenu. Would that do it? It obviously doesn't bring up the ContextMenu on a LeftButton DoubleClick... And if that is the case, do I need to make a choice between having a ContextMenu or having DoubleClick?

MouseUp:
        private void lstRight_MouseUp(object sender, MouseEventArgs e)
        {
            // Bring up Edit Trainee Context Menu
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                int index = lstRight.IndexFromPoint(e.Location);
                {
                    if (lstRight.SelectedItems.Count > 0)
                    {
                        ctxMenuEditTrainee.Show(Cursor.Position);
                    }
                }
            }
        }
 
Try commenting out the code that brings up the context menu to see if it makes a difference.
 
Try commenting out the code that brings up the context menu to see if it makes a difference.
I must be tired today. Should've tried that. But unfortunately, even removing the Entire MouseUp routine did nothing to solve the problem.
 
So, in the end, I ended up calling the ContextMenu from the WndProc instead of using the MouseUp and that seemed to do the trick. Now the MouseDoubleClick works.

ListBox MouseDoubleClick:
        private void lstRight_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if( lstRight.SelectedItem != null )
            {
                MoveSelectedItems(lstRight, lstLeft);
            }
        }

WndProc ContextMenu:
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            // Listen for operating system messages.
            switch (m.Msg)
            {
                case WM_CONTEXTMENU:
                    if (lstRight.SelectedItems.Count > 0)
                    {
                        ctxMenuEditTrainee.Show(Cursor.Position);
                        return;
                    }
                    break;
            }
            base.WndProc(ref m);
        }
 

Latest posts

Back
Top Bottom