DoublePressing ListBox

Xojo 2022r3
Mac
I have had trouble with code that relies on detecting in a ListBox where a double-click occurs. Row and Column are not included in the context of detecting a DoublePressed event. This seems peculiar.

So I can go to the documentation and there seems to be a section devoted specifically to answering this question. I include this below. They say the putting some code in the MouseDown event (which does have row/column information) will do the trick. When I use the suggested code, it does fire off the message when I double click.

But as I would expect, it also fires off the identical message after single-clicking on the ListBox. So, as I see it, this is of no particular use. It does not help me with determining where the double-click occurred. I can accept the additional complication and maintain a global variable which stores the last column and row click and then access this information from DoublePressed event. That sort of works, but I wonder if I am missing something and wonder why this suggested code occurs in the documentation because it does not seem to be of any value.

I say “sort of works” because I am trying to distinguish between a single click on a previously selected item and a double-click on that item. With a single-click, I want it to unselect and with a double-click I want it to preform a specific task related to double clicking. But the first click then effectively unselects the item so the second click is seen as a click on an unselected item.

Anyway, I am asking because I want to know if there is something that I am missing and somehow the code provided in the documentation makes sense. And can anyone shed light on why the code of DoublePressed event contains in itself no row / column information? It seems to be natural that it would.

Determining which cell was double-clicked

The DoublePressed event fires when the user double-clicks anywhere inside a DesktopListBox, but the indexes of the cell that was double-clicked are not passed. You can determine which cell was double-clicked with the RowFromXY and ColumnFromXY methods. They use the x,y mouse coordinates where the double-click took place and translate them into the row and column indexes of the cell that was clicked. You need to adjust for the location of the ListBox on the screen relative to the top-left corner of the display.

This code in the MouseDown event obtains the indexes of the cell that was double-clicked.

Var row, column As Integer
row = Me.RowFromXY(x, y)
column = Me.ColumnFromXY(x, y)
MessageBox("You double-clicked in cell " + row.ToString + ", " + column.ToString)

On single-click, I tend to store the coordinates and then use the stored values if a double-click is signalled. You can’t get a double-click without a single-click having occurred so the stored values are bound to be correct.

The code in the documentation assumes that you do nothing on a single click. You just want to react to a double click and know what was clicked on. Your case is a lot more complicated, since you want to act on both a single and a double click.

The code in the documentation assumes that you do nothing on a single click.

But the code in the documentation does not do nothing on a single click. It throws up the message box. It does not do anything that is specific to the double-click. It basically ignores the DoublePressed event itself.

Same problem here. I hope not this is solved by creating a timer. I have added this to the top of the CellPressed in the Listbox, and a Property theTicks added:

if System.Ticks-theTicks<30 then MessageBox str(System.Ticks-theTicks)
theTicks=System.Ticks

It is compact and works fine, but CellPressed is executed first, for me that’s ok.

My version to recognize the listbox selection

https://www.dropbox.com/s/8d5md7wghhar2c4/listbox-doppelklick-selecd-test.xojo_binary_project?dl=1

CellPressed is executed BEFORE Double Pressed, just after 1st pressing. Read and store row & column during CellPressed event and then use them in Double Pressed event.