ListBox.ColumnFromPoint

From Xojo Documentation

Method

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

New in 2019r2

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.RowFromPoint(xValue, yValue)
column=Me.ColumnFromPoint(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.RowFromPoint(xValue, yValue)
column=Me.ColumnFromPoint(xValue, yValue)

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

See Also

System.MouseX, System.MouseY