MouseColfunction
Returns the current mouse position, in column coordinate.
Syntax
FUNCTION MouseCol () AS LONG
Description
Returns the zero-based index of the column under the mouse pointer.
Remarks
Unlike the Col property (which indicates the selected or active column), MouseCol tracks the mouse cursor's horizontal position dynamically as it moves across the grid.
It automatically translates the mouse's X-coordinate (horizontal) into the corresponding column index, accounting for current scroll positions and column widths.
If the mouse is over a fixed column (the gray area on the left), MouseCol returns the index of that fixed column (e.g., 0).
If the mouse is over a scrollable data column, the returned value corresponds to that column’s index.
If the mouse is within the control's boundaries but to the right of the last column, the property returns -1.
Internally, the control converts the mouse’s horizontal pixel coordinate into a column index, taking into account:
- current horizontal scroll position
- individual column widths
- fixed vs. scrollable column regions
Example
Dim targetCol As Long = grid.MouseCol DIM targetRow As Long = grid.MouseRow If targetCol <> -1 And targetRow <> -1 Then Print "You right-clicked Column: " & STR(targetCol) & " in Row: " & STR(targetRow) End If
Reference
- Documented in Windows/Windows GUI/MSHFlexGrid Class.md
- Topic: Microsoft Hierarchical Grid