Determining which cell was double-clicked in API 2.0

Hi everybody,

I’m quite new here.

I’m trying to convert an older plugin I could make use of to API 2.0. I have done a lot of the work so far, and it is helping me to understand this new API. I come from a VB background so there is a learning curve, but I like learning new things.

Currently I am stumped.

There is code in the plugin which is almost copy/paste of the section Determining which cell was double-clicked.

API 2.0 does not know what to do with “Me.Parent.Top” (or .left, etc.) and, honestly, neither do I.

Var row, column As Integer
row = Me.RowFromXY(System.MouseX - Me.Left - Self.Left - Me.Window.Left, System.MouseY - Me.Top - Self.Top - Me.Window.Top)
column = Me.ColumnFromXY(System.MouseX - Me.Left - Me.Parent.Left - Me.Window.Left, System.MouseY - Me.Top - Me.Parent.Top - Me.Window.Top)
MessageBox("You double-clicked in cell " + row.ToString + ", " + column.ToString)

Any assistance would be appreciated,
Thank you.

Did I post this in the wrong forum? I do not see a forum that appears to target API 2.0.

No this is the correct forum.

I don’t use API 2.0 as it’s too risky to update my existing apps, however it seems that Xojo decided to make the .parent property an object (instead of rectControl), so you need to check if it’s a rectControl or a window, before trying to read it’s top position.

I would recommend that you consider grabbing the mouseLocation in the mouseDown event and stuffing it into a property of the listbox, so that on the double click event you already have a mouse location that’s already been localized to the listbox.

Parent As Object

Used to get and set the control’s parent control or window.

If the control is on the window, the Parent will be the Window. If the control is on the container, the Parent will be the container. If the control is completed enclosed by another control, the Parent will be that DesktopUIControl.

If you do not want the enclosing control to be the parent, set the Parent property of that control to Nil to make it the Window.

If the parent control is somehow in another window, an InvalidParentException will occur.

The following example sets the parent of the control to the window.

As this is code for a control that is known to be on a DesktopContainer you can just do this:

Var row, column As Integer
row = Me.RowFromXY(System.MouseX - Me.Left - Self.Left - Me.Window.Left, System.MouseY - Me.Top - Self.Top - Me.Window.Top)
column = Me.ColumnFromXY(System.MouseX - Me.Left - DesktopContainer(Me.Parent).Left - Me.Window.Left, System.MouseY - Me.Top - DesktopContainer(Me.Parent).Top - Me.Window.Top)
MessageBox("You double-clicked in cell " + row.ToString + ", " + column.ToString)

Thanks for the tip, I read that passage already but I guess I am still to new to Xojo, seems that code samples and snippets are helping me more than descriptive discussions.

Thank you, again, though.

Just add "DesktopContainer(). Nice and simple, thanks.

Again, I come from a VB background so a lot of what was in RealBasic made sense to me. But I have gotten lost in the weeds a few times with all the changes to API 2.0. I am hopeful that I will find more simple examples like what you have provide here, as more questions arise.

Thanks for the solution.

So you like Xojo Documentation…

I guess this is not what he meant.

Maybe, but no one can tell the Xojo Documentation have prose (tons of text); only the essential, and more or less examples all around.

And we have in the Examples Projects folder; > 100MB / 923 items… to watch for learning.

“Descriptive discussions” - Maybe I should have been clearer. The “discussions” I was referring to would be the text accompanying the samples and example code in the documentation.

My “mileage” in the Documentation has varied. But let’s be fair, that has been true of any language I have used.

I guess my issue - IF I was going to claim to have one - would be a desire to have the documentation for API 2.0 include examples or some links to “this not that” examples for people dealing with all the changes.

For example: I can find plenty of interesting things in the docs about what DesktopContainer does, with several examples. But I did not know I needed to make use of DesktopContainer in this instance, without asking for help. When I search for [xojo api 2.0 “DesktopContainer(me.parent)”] in Google (Not the end all/be all search engine, but it works well enough for this example.) I get nothing. When I search for [xojo api 2.0 “me.parent”] I get interesting results but none show an example like the sample code in my original post with DesktopContainer inserted into it, like the API 2.0 solution.

If there was an API 2.0 doc for “Determining which cell was double-clicked” with the modified example it would be easy to compare, see where I went wrong and encourage me to learn more about DesktopContainer.

That document may exist one day. Until it and probably hundreds, if not thousands like it, exist questions like mine, at the start of this thread, will continue.

I am grateful that this forum exists so we have someplace where we can fill-in-the-gap.

I’m surprised nobody mentioned the trick of tracking the last cell clicked which is given to you by CellPressed(Row As Integer, Column As Integer, X As Integer, Y As Integer) As Boolean. You can use properties to keep the row and column given by this event.

1 Like

In terms of knowing which cell was clicked, AFAIK there is no difference between API 1 and API2 except the names of some of the event handlers have changed. But not so much that you wouldn’t guess which is which.

The technique hasn’t changed either. Just follow what @Sam_Rowlands said upthread: in MouseDown memorise the X and Y and then use them with RowFromXY and ColumnFromXY in the DoublePressed event handler.

Sam did give a perfectly valid solution but…

The code I am modifying (as a way of becoming familiar with 2.0) includes an almost copy/paste of the example in “Determining which cell was Double-Clicked”.

Julian’s reply took that same code and modified it with DesktopContainer and a pair of parens.

So, in this instance there was a slight but significant difference between API 1 and 2. Not a big deal but if your new it’s the little things like that which trip you up.

Considering my starting point Julian’s answer explained why it wasn’t working in 2.0 and how to correct it with ease.

Maybe the answer you favor (Sam’s) is the better one if not modifying someone else’s code.

But, to anyone who searches for determining which cell was double-clicked Julian’s solution is perfect.

I mentioned grabbing it in the mouseDown event.