DesktopListBox.RowFromXY

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
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 control. 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 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 code is not in the control 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.Window.Left // Calculate current mouse position relative to top left of ListBox

Var yValue As Integer
yValue = System.MouseY - Me.Top - Self.Top - Me.Window.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