![]() |
![]() |
Tutorial - Virtual Events Mode |
In this tutorial, you will learn how to use the Virtual Events data mode to display an array of variants. This tutorial covers reading, updating, adding and deleting records in the Virtual Events mode.
'variable to hold the data to be displayed in the grid
Private arData As Variant
'current rows count
Private mlRowsCount As Long
'max row count
Private Const MAX_ROWS = 100
Private Sub Form_Load()
mlRowsCount = 4
ReDim arData(SGGrid1.DataColCount - 1, mlRowsCount)
SGGrid1.DataRowCount = mlRowsCount
End Sub
Private Sub SGGrid1_VirtualReadData(ByVal RowBuffer As IsgRowBuffer)
Dim i As Integer
For i = 0 To RowBuffer.ColumnCount - 1
RowBuffer.Value(i) = arData(i, RowBuffer.RowIndex)
Next
If RowBuffer.RowIndex = mlRowsCount Then
RowBuffer.RowIndex = -1
End If
End Sub
Private Sub SGGrid1_VirtualWriteData _
(ByVal RowBuffer As IsgRowBuffer, Cancel As Boolean)
Dim i As Integer
For i = 0 To RowBuffer.ColumnCount - 1
arData(i, RowBuffer.RowIndex) = RowBuffer.Value(i)
Next
End Sub
Private Sub SGGrid1_VirtualAddRow _
(ByVal RowBuffer As IsgRowBuffer, Cancel As Boolean)
Dim i As Integer
If MAX_ROWS = mlRowsCount Then
Cancel = True
Exit Sub
End If
mlRowsCount = mlRowsCount + 1
If mlRowsCount > UBound(arData, 2) Then
ReDim Preserve arData(RowBuffer.ColumnCount - 1, mlRowsCount + 10)
End If
For i = 0 To RowBuffer.ColumnCount - 1
arData(i, mlRowsCount - 1) = RowBuffer.Value(i)
Next
End Sub
Private Sub SGGrid1_VirtualDeleteRow _
(ByVal RowIndex As Long, ByVal RowBookmark As Variant, _
Cancel As Boolean)
Dim i As Integer, j As Integer
mlRowsCount = mlRowsCount - 1
For i = RowIndex To mlRowsCount
For j = 0 To UBound(arData, 1)
arData(j, i) = arData(j, i + 1)
Next
Next
End Sub
SGGrid1.Groups.Add "Band", sgSortAscending, sgSortTypeString, False, True
See Also
DataMode | VirtualReadData | VirtualWriteData | VirtualAddRow | VirtualDeleteRow