# 将阵列放进DBGrid显示

Posted by Albert on January 12, 1999 at 13:45:41:

Private Sub Comm_Click()
DBG_Var TestVar
End Sub

Private Sub DBGrid_UnboundReadData(ByVal RowBuf As MSDBGrid.RowBuffer, StartLocation As Variant, ByVal ReadPriorRows As Boolean)
DBG_URD RowBuf, StartLocation, ReadPriorRows, TestVar
End Sub

Private Sub DBGrid_UnboundGetRelativeBookmark(StartLocation As Variant, ByVal OffSet As Long, NewLocation As Variant, ApproximatePosition As Long)
DBG_UGRB StartLocation, OffSet, NewLocation, ApproximatePosition, TestVar
End Sub

'DBGrid显示
Public Sub DBG_URD(RowBuf As MSDBGrid.RowBuffer, StartLocation As Variant, ReadPriorRows As Boolean, ByVal DBGVar As Variant)
If IsEmpty(DBGVar) Then Exit Sub
Dim rowsFetched%
Dim incr%
Dim curRow%
Dim J%
rowsFetched% = 0
If ReadPriorRows Then
incr% = -1 ' Reading data backward
Else
incr% = 1 ' Reading data forward
End If

If IsNull(StartLocation) Then
If ReadPriorRows Then
curRow% = UBound(DBGVar, 2) - 1 ' Reading data from the last row
Else
curRow% = 0 ' Reading data from the first row
End If
Else
curRow% = Val(StartLocation) + incr%
End If

Dim I%
I% = 0

While I% < RowBuf.RowCount
If curRow% < 0 Or curRow% >= (UBound(DBGVar, 2) + 1) Then
RowBuf.RowCount = rowsFetched%
Exit Sub
End If
For J% = 0 To UBound(DBGVar, 1)
RowBuf.Value(I%, J%) = DBGVar(J%, curRow%)
' RowBuf.Value(I%, 1) = DBGVar(1, curRow%)
' RowBuf.Value(I%, 2) = DBGVar(2, curRow%)
Next J%
RowBuf.Bookmark(I%) = curRow%

curRow% = curRow% + incr%
rowsFetched% = rowsFetched% + 1
I% = I% + 1
Wend

RowBuf.RowCount = rowsFetched%
End Sub

Public Sub DBG_UGRB(StartLocation As Variant, OffSet As Long, NewLocation As Variant, ApproximatePosition As Long, ByVal DBGVar As Variant)
If IsEmpty(DBGVar) Then Exit Sub
Dim curRow%
If IsNull(StartLocation) Then
If OffSet < 0 Then
curRow% = OffSet + UBound(DBGVar, 2) ' Reading data from the last row
Else
curRow% = OffSet - 1 ' Reading data from the first row
End If
Else
' Positioning from StartLocation plus the OffSet
curRow% = Val(StartLocation) + OffSet
End If

If curRow% < 0 Or curRow% >= UBound(DBGVar, 2) Then
NewLocation = Null
Else
NewLocation = curRow%
ApproximatePosition = curRow% + 1 ' One based
End If

End Sub

Follow Ups:

- Re: 将阵列放进DBGrid显示(能不能讲清楚一点，能不能有完整范例) Tim 08:30:46 1/13/99 (0)