Hi Lane,
The TrueDBGrid control does have properties and methods for calculating coordinates of grid elements, such as
RowTop,
RowHeight,
RecordSelectorWidth and so on. I've put this all together and, after some experimenting, come up with the following function that calculates coordinates of a grid row indicator given the row index and then clicks on it:
' Click the indicator of the grid row specified by the 0-based index
Sub ClickRowIndicator(grid, rowIndex)
If rowIndex < 0 Or rowIndex >= grid.ApproxCount Then
Log.Error "Row index " & rowIndex & " is out of bounds 0 .. " & grid.ApproxCount & "."
Exit Sub
End If
If Not grid.RecordSelectors Then
Log.Error "Cannot click the row indicator because they are not displayed in the grid."
Exit Sub
End If
' Set the current row and scroll the grid to make it visible
grid.Bookmark = CDbl(rowIndex + 1) ' In our example, the Bookmark property holds the 1-based row index and is of the Double type
Dim x, y, xTwips, yTwips
' Calculate coordinates of the row indicator, in VB twips
xTwips = grid.RecordSelectorWidth / 2
yTwips = grid.RowTop(grid.Row) + grid.RowHeight/2
' Convert twips to pixels
x = CLng(TwipsToPixelsX(xTwips))
y = CLng(TwipsToPixelsY(yTwips))
Log.Message "Clicking indicator of grid row " & rowIndex & "..."
grid.Click x, y
End Sub
Const TWIPSPERINCH = 1440
Function TwipsToPixelsX(XTwips)
Dim Xdpi
Xdpi = Win32API.GetDeviceCaps(Win32API.GetDC(0), Win32API.LOGPIXELSX)
TwipsToPixelsX = XTwips / TWIPSPERINCH * Xdpi
End Function
Function TwipsToPixelsY(YTwips)
Dim Ydpi
Ydpi = Win32API.GetDeviceCaps(Win32API.GetDC(0), Win32API.LOGPIXELSY)
TwipsToPixelsY = YTwips / TWIPSPERINCH * Ydpi
End Function
Usage example:
Sub Test
Dim grid
Set grid = Sys.Process("Ub2RsCls").VBObject("UB2ADO").VBObject("TDBGrid1")
ClickRowIndicator grid, 0
ClickRowIndicator grid, 3
ClickRowIndicator grid, 7
End Sub
You may need to tweak the code slightly for your specific grid object (e.g. if it uses splits). Anyway, give it a try and let me know how it works for you.