Listbox drag and mouse event handler interactions

I’ve been using the DragRow, DragOver, and DragReorderRows events to allow the user to reorganise the rows in their listbox. This works without problems. At the same time, I use the CellClick event to allow the user to effect another, separate, action when they click a row. The only problem here is that clicking and holding the mouse to effect the drag is also caught as a CellClick action, so the two actions interfere. In addition, the separate non-drag action also happens immediately the mouse is pressed. I would actually like the separate action to occur when the mouse is released, as that would allow the user to change their mind.

So, I thought I’d use MouseDown and MouseUp instead of CellClick, but adding a MouseDown handler to the mix kills all the drag actions. They no longer work, just as if the Drag handlers were not implemented at all.

How can I stop the MouseDown event handler from interfering with the drag logic?

I’m using 2019r3.1. I posted on the forum but don’t expect to get any replies there.

Events when doing selection and dragging can get confusing.

How about you do a context menu instead of using a CellClick?


Interesting idea - thanks. I already have a context menu, so it would be easy enough to add another entry there. Hah - I bet now I’ll find that if I remove the CellClick handler, the drag stuff will not work. :rofl:

I’ll give it a try. I must say it would be nice if Xojo were to document these event handler interactions.

Not tried but:

Add a boolean property clicked
In MouseDown set it to true
In MouseDrag set it to false
In MouseUp do

If clicked then 
  clicked = false
End if

The fundamental problem is that as soon as I added the MouseDown handler, the Drag events ceased to fire at all. If they fired, then adding some interlock logic would probably be straightforward. But they don’t.

What are you returning from MouseDown? (Not at my Mac)

What Markus is getting at is this in the docs on MouseDown:

Return True if you are going to handle the MouseDown. In such a case:

  • The Action event, if any, will not execute and the state of the object will not change.
  • You will receive the MouseDrag and MouseUp events.

If you return False, the system handles the MouseDown so the above event handlers do not get called.

1 Like

Yeah, I know. I read that too. I’ve tried returning True and False in MouseDown, makes no difference. The Drag handlers are simply not called (to check, I put breakpoints at the start of each).

MouseDrag might fire, but DragReorderRows does not (and the drag is blocked)

So returning True in MouseDown means you have to deal with EVERYTHING afterwards yourself: selecting the row, dragging, dropping, reordering.

Can you use the DoubleClick event instead? No problem there.

OK, just tested again, perhaps more carefully. When testing with MouseDown yesterday it seemed that any return value would prevent the Drag actions, but today I see it’s only when returning True. Unfortunately I need to return True in order to have the MouseUp event fire. Double-click I use for something else already.

So, it’s looking more like I’ll implement Beatrix’ suggestion and add the single-click action to the context menu.