DesktopListBox.RowFromXY

From Xojo Documentation

Method

DesktopListBox.RowFromXY(X as Integer,Y as Integer) As Integer

New in 2021r3

Supported for all project types and targets.

Returns the row index from the passed mouse x, y pixel coordinates.

Notes

The parameters X and Y are relative to the top, left corner of the DesktopListBox. If you use System.MouseX or System.MouseY to get the mouse coordinates to use with this method, you'll need to take into account that those System values are relative to the top-left corner of the entire screen.

Examples

This code in the DoublePressed event of a DesktopListBox added to a Window obtains the indexes of the cell that was double-clicked:

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

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

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

MessageBox("You double-clicked in cell " + row.ToString + ", " + column.ToString)

If the DesktopListBox code is not on the window (perhaps it is in a subclass or DesktopContainer), then you need to be sure to calculate the correct offsets. This code would be used for a DesktopListBox on a DesktopContainer:

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

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

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

MessageBox("You double-clicked in cell " + row.ToString + ", " + column.ToString)

See Also

DesktopListBox.ColumnFromXY, System.MouseX, System.MouseY