In a ListBox cell I need to have the sigle click to put it into edit mode but if I double click I need to start a different action.
I wrote a CellClick code and a DoubleClick code but, whatever I do, it only responds to the single click.
when you single clic, you put in edit mode. ok but this makes the double clic never happen.
you should not put in edit mode after a single clic, but butter using a contextual menu.
also good to use a contextual menu to perform some “other” actions.
for me double)clic is to open a topic, or edit its name.
Differentiating between the double and simple click is still doable even with the original approach. You can do this:
• Add a timer to the window (or listbox’s class)
• In CellClick, you set the timer’s period to later than a double click time (you can get how to do that in the Language Reference) and the mode to 1 (once)
• In DoubleClick, you set the timer’s mode to off. At this point, the timer will execute after a CellClick occurred and which hasn’t been followed by a DoubleClick.
• In DoubleClick, also add the code for when the user double clicks.
• In the timer’s action event, put the code initially found in the CellClick event (the code to be executed for a regular click, in this cas, set the edit mode).
I agree with this except that it means that the effect of every single-click is delayed.
It might perhaps be better not to use the single-click event, but instead to use mouse-up to run the single-click code. This also allows you to use mouse-exit to cancel the whole action. If the user does mouse-down in the cell, but decides not to proceed, they can drag the mouse out of the cell before doing mouse-up.
To make this work requires a flag that you set on mouse-down, and clear it on mouse-up and mouse-exit. Then, in mouse-up, you test this flag before running the single-click code, and do nothing if it is not set.
I use this in a number of places in my app, and perhaps there one or two more, too.
If you set the timer’s period to the length of a double click (as defined by the user’s preferences), the delay would be close to equal as the possibility to differentiate anyway, I think.
Would also work (and avoids using a timer); this somehow replicates the way Xojo handles the DoubleClick event, I guess.
I’m trying your solution but how do you clear the flag on mouse-up or exit to have double click working?
Even in a double click you are going to have a mouse down event set to true
Put the code to clear it in the MouseUp and MouseExit events. The double-click will work anyway. Don’t forget to move the single-click code to the MouseUp event, and then remove the single-click event handler altogether.
Hmmm. Now I see you’re doing this on a Listbox. That will be more complicated as the events apply to the whole listbox, not to a particular cell. I need to do some tests to see how this might work - sorry.
Yes, might be better. I just tried to make the approach I described earlier work with listbox and I failed. I can make it work without double-click, but if I want mouseup then I don’t seem to get double-click. Where I had used this before was with a button made from a canvas, but of course one doesn’t need the double-click there …
Annoying as I had hoped to use this to improve my own listbox.