Type | Description | |||
Vertical as Boolean | A boolean expression that specifies the scrollbar being requested. True indicates the Vertical scroll bar, False indicates the Horizontal scroll bar. | |||
Long | A long expression that defines the scroll bar position. |
The following VB sample scrolls to the row 10,000:
With Grid1 .ScrollPos(True) = 10000 End With
The following VB sample gets the cell's coordinates to let user aligns nicely a context popup menu:
Private Sub getCellPos(ByVal g As EXGRIDLibCtl.Grid, ByVal hItem As EXGRIDLibCtl.hItem, ByVal nColumn As Long, X As Long, Y As Long) X = -g.ScrollPos(False) With g Dim c As EXGRIDLibCtl.Column For Each c In .Columns If (c.Visible) Then If (c.Position < .Columns(nColumn).Position) Then X = X + c.Width End If End If Next Y = 0 If (.HeaderVisible) Then Y = Y + .HeaderHeight End If With .Items Dim i As EXGRIDLibCtl.hItem i = .FirstVisibleItem() While Not (i = hItem) And Not (i = 0) Y = Y + .ItemHeight(i) i = .NextVisibleItem(i) Wend End With End With End Sub
The getCellPos method gets the x, y client coordinates of the cell ( hItem, nColumn ). The hItem indicates the handle of the item, and the nColumn indicates the index of the column. Use the ClientToScreen API function to convert the client coordinates to screen coordinates like bellow:
Private Type POINTAPI x As Long y As Long End Type Private Declare Function ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
In VFP, use 1 instead .t. for changing the ScrollPos property like follows:
list1.object.scrollpos(1) = 123
instead
list1.scrollpos(.t.) = 123
In the following MouseDown handler the ItemFromPoint method determines the cell from the cursor. The sample displays an exPopupMenu control at the beginning of the cell, when user right clicks the cell:
Private Sub Grid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) If Button = 2 Then With Grid1 Dim h As EXGRIDLibCtl.hItem, c As Long, hit As EXGRIDLibCtl.HitTestInfoEnum h = .ItemFromPoint(X / Screen.TwipsPerPixelX, Y / Screen.TwipsPerPixelY, c, hit) If Not (h = 0) Then ' Selects the item when user does a right click Grid1.Items.SelectItem(h) = True ' Gets the client coordinates of the cell Dim xCell As Long, yCell As Long getCellPos Grid1, h, c, xCell, yCell ' Converts the client coordinates to the screen coordinates Dim p As POINTAPI p.X = xCell p.Y = yCell ClientToScreen Grid1.hwnd, p ' Displays the exPopupMenu control at specified position PopupMenu1.HAlign = EXPOPUPMENULibCtl.exLeft Debug.Print "You have selected " & PopupMenu1.Show(p.X, p.Y) End If End With End If End Sub