Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer) Me.Caption = DataGrid1.RowEnd Sub
这个不行,我都把滚动条拉到100多行了,还显示20多行,.Row是从顶端算起,上面还有记录. Private Sub DG_jldlb_Click() selrow = DG_jldlb.Row MsgBox selrow End Sub
Private Sub DataGrid1_Click() aa = DataGrid1.Row End Sub
应该看ado的Recordset的AbsolutePosition 属性。。
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Private Type SCROLLINFO cbSize As Long fMask As Long nMin As Long nMax As Long nPage As Long nPos As Long nTrackPos As Long End TypePrivate Declare Function GetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, LPSCROLLINFO As SCROLLINFO) As Long Private Const SIF_POS = &H4 Private Sub Command1_Click() MsgBox DataGrid1.Row + GetVScrollPos() End Sub Private Function GetVScrollPos() Dim lHwnd As Long Dim l As Long Dim s As String * 260 Dim mInfo As SCROLLINFO
Me.Caption = DataGrid1.RowEnd Sub
Private Sub DG_jldlb_Click()
selrow = DG_jldlb.Row
MsgBox selrow
End Sub
aa = DataGrid1.Row
End Sub
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Type SCROLLINFO
cbSize As Long
fMask As Long
nMin As Long
nMax As Long
nPage As Long
nPos As Long
nTrackPos As Long
End TypePrivate Declare Function GetScrollInfo Lib "user32" (ByVal hwnd As Long, ByVal n As Long, LPSCROLLINFO As SCROLLINFO) As Long
Private Const SIF_POS = &H4
Private Sub Command1_Click()
MsgBox DataGrid1.Row + GetVScrollPos()
End Sub
Private Function GetVScrollPos()
Dim lHwnd As Long
Dim l As Long
Dim s As String * 260
Dim mInfo As SCROLLINFO
lHwnd = FindWindowEx(Me.DataGrid1.hwnd, 0, "ScrollBar", vbNullString)
Do While lHwnd <> 0
l = GetWindowText(lHwnd, s, 260)
If UCase(Left(s, l)) = UCase("DataGridSplitVScroll") Then
'如果找到VScroll那么获取当前的值
mInfo.fMask = SIF_POS
mInfo.cbSize = LenB(mInfo)
GetScrollInfo lHwnd, 2, mInfo
GetVScrollPos = mInfo.nPos
End If
lHwnd = FindWindowEx(Me.DataGrid1.hwnd, lHwnd, "ScrollBar", vbNullString)
Loop
End Function
呵呵,突发奇想,用VScrollBar来获取滚动条当前状态,再进行判断,可能这个方法是绕远了一点,仅作参考