ListBox.ColumnFromXY

From Xojo Documentation

Revision as of 22:46, 29 August 2019 by Gperlman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Method

ListBox.ColumnFromXY(X as Integer,Y as Integer) As Integer

Supported for all project types and targets.

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

Notes

The parameters X and Y are relative to the top, left corner of the ListBox. 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 DoubleClick event of a ListBox 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 you use the ListBox on a ContainerControl, then you need to also take into account the Container size:

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

System.MouseX, System.MouseY