雖然賦值成功,但是datagridMILY: 宋體; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">無法顯示你需要的數據(這里需要研究一下),因為時間的緣故,就用第二種方式坐標的方式來實現,考慮多平臺共享使用,寫SetGridFocus函數,思路這樣得到tdbgrid對象,得到其中column的屬性寬高,計算坐標(這些都在函數內部實現),其中移動有個固定值24是追蹤tdbgrid代碼中defaultHeight為24
最后代碼如下:
Sub SetGridFocus(strObject as String, strCol as String, strRow as String, strValue as String)
Dim iResult as Integer
Dim iCount as Integer
Dim ColWidth() as integer
Dim iWidth as Integer
Dim strColPos as Integer
Dim strRowPos as Integer
Dim strCor as String
Dim iTemp as integer
strColPos = 0
strRowPos = 0
iTemp = 0
SQAGetProperty strObject ,"Columns.Count", iCount
if iCount <> 0 then
Redim ColWidth(iCount - 1)
While iTemp < iCount
iResult = SQAGetProperty (strObject, "Columns.Items(" + CStr(iTemp) +").Width",iWidth)
ColWidth(iTemp) = iWidth
iTemp = iTemp + 1
wend
End if
strColPos = 20
if CInt(strCol) <> 1 then
for iTemp = 1 to CInt(strCol)-1
strColPos = strColPos+ ColWidth(iTemp-1)
next iTemp
End if
for iTemp = 1 to CInt(strRow)
strRowPos = 24 +strRowPos
next iTemp
strCor = "Coords=" & strColPos &","+CStr(strRowPos)
GenericObject Click, strObject, strCor
InputKeys strValue
stop
strCor = "Coords=" & strColPos &","+CStr(strRowPos + 24)
GenericObject Click, strObject, strCor
End Sub
上編寫的還有很多疏漏的地方,對于浮動文本框賦值成功,卻無法改動tdbgrid中的值沒有深入研究,該函數在實際應用中還有個小問題,沒有做到很完全“周到“ ,下回有時間改正。
備注:
最后我把代碼進行優化和擴展,開發了針對grid的相關函數,下邊是其中之一
//得到列數
Function GetColCount(sGridRecogStr as String) as Integer
Dim Result as Integer
Dim vValue as Variant
Dim sLogMessage as String
Dim sErrorMessage as String
grdGetRowCount = -1
Result = SQAGetProperty(sGridRecogStr, "Column.Count", vValue)
If Result = sqaSuccess Then
GetRowCount = CInt(vValue)
Else
sLogMessage = "無法得到Grid的列數”
sErrorMessage = "[" & CStr(Result) & " = " & Error(Result) &"]"
SQALogMessage sqaFail, sLogMessage, sErrorMessage
End If
End Function
就到這里吧。