What causes RowFromXY to fail?

I have this set of lines in a listbox and it is suddenly failing. It is giving me -1 for a row. If I step into them nothing happens. Suggestion?

Dim row As Integer = me.RowFromXY(System.MouseX - me.Left - Self.Left, System.MouseY - me.Top - Self.Top) Dim column As Integer = me.ColumnFromXY(System.MouseX - me.Left - Self.Left, System.MouseY - me.Top - Self.Top) me.ListIndex = row

Is which event are you calling this?

Also, which version of Xojo are you using an on which OS?

If this is in MouseMove, you wouldn’t need System.MouseX, just the given x and y.

Sorry forgot to include event. MouseDown and gotfocus. It especially confusing since MouseDown includes X and Y.

Well I’ve found one bug in it, when the listbox spans a monitor edge between two monitors of different scale settings. That’ll return at -1,-1. That’s quite an edge case (pun intended) :smiley:

I’ll report that if its not there already.

Yeah, you’ll need to use x and y instead of System.MouseX and System.MouseY.

Actually you dont, -1,-1 is just returned when a hit is detected outside of a row item (i.e. on the white of the background under the last entry of the list)

You just don’t see it in a DoubleClick event because the doubleclick doesnt fire if you hit the white space.

That’s the confusion, since I’m actually selecting a valid row in the list. I can’t find something yet that just reads a row, and cellclick isn’t valid since it’s readonly
I did get the code for doubleclick, but it’s repurposed.
Also. the listindex isn’t being reset. If I comment out the above code the listindex hasn’t been reset.

I can’t see a reason for putting it in GotFocus, that will depend where the mouse is at the time of the focus switch and will return -1,-1 unless the mouse happens to be in the control when focus moves to the control (i.e. wont fire if alt-tabbing to the window unless the mouse is in the right place). It then will never fire again until focus is moved off the listbox.

TypeNormal (default) is read only, that should be firing on MouseDown.

The following is lifted straight from the ListBox.RowFromXY language reference and works as expected in a read only (default) listbox inside MouseDown without changing anything, it also works in DoubleClick but doesnt fire when clicking in the white space (explained in previous post above).

[code]Function MouseDown(x As Integer, y As Integer) Handles MouseDown as Boolean
'System.DebugLog(“x=” + Str(x) + " System.MouseX=" + Str(System.MouseX))

Dim xValue As Integer
xValue = System.MouseX - Me.Left - Self.Left // Calculate current mouse position relative to top left of ListBox

Dim yValue As Integer
yValue = System.MouseY - Me.Top - Self.Top // Calculate current mouse position relative to top of ListBox.

Dim row, column As Integer
row = Me.RowFromXY(xValue, yValue)
column=Me.ColumnFromXY(xValue, yValue)

MsgBox("You double-clicked in cell " + Str(row) + ", " + Str(column))
End Function
[/code]

I tried that code too. No change.
I double-checked on type for my readonly list and it’s “0”.
The one with gotfocus is readable.

[quote=360648:@Arthur Gabhart]I have this set of lines in a listbox and it is suddenly failing. It is giving me -1 for a row. If I step into them nothing happens. Suggestion?

Dim row As Integer = me.RowFromXY(System.MouseX - me.Left - Self.Left, System.MouseY - me.Top - Self.Top) Dim column As Integer = me.ColumnFromXY(System.MouseX - me.Left - Self.Left, System.MouseY - me.Top - Self.Top) me.ListIndex = row [/quote]

what do you wanna do?

if you click on a row then listindex is the row you clicked.

my code for edit cell in doubleclick is

		Dim xValue As Integer
		xValue = System.MouseX - Me.Left - Self.Left
		
		Dim yValue As Integer
		yValue = System.MouseY - Me.Top - Self.Top
		
		Dim row, column As Integer
		row = Me.RowFromXY(xValue, yValue)
		column=Me.ColumnFromXY(xValue, yValue)
		
		if column < me.ColumnCount Then
				me.EditCell row, column
				me.ActiveCell.UseFocusRing = false
		end if

[quote=360667:@Arthur Gabhart]I tried that code too. No change.
I double-checked on type for my readonly list and it’s “0”.
The one with gotfocus is readable.[/quote]

How many columns and rows do you have?
What OS are you on?
What Xojo version are you using?

It is on a Mac. I am trying now one other thing. Rebooting

If in doubt, poke it in the eye :wink:

Grumble. Rebooting didn’t work. I moved the code to cellclick and it works.