![]() |
![]() |
Tutorial - Virtual Interface |
In this tutorial, you will learn how to use the Virtual Interface data mode to display an array. It demonstrates how to implement the IsgGridDataSource interface and how to use its functions to implement read, update, add and delete operations.
Implements IsgGridDataSource
'variable to hold the data to be displayed in the grid
Private arData() As Long
'current rows count
Private mlRowsCount As Long
Private Sub Form_Load()
mlRowsCount = 2
ReDim arData(mlRowsCount) As Long
'speed up data input
SGGrid1.EnterKeyBehavior = sgEnterKeyRows
Set SGGrid1.SimpleDataSource = Me
arData(0) = 100
arData(1) = -100
End Sub
Private Function IsgGridDataSource_GetRowCount() As Long
IsgGridDataSource_GetRowCount = mlRowsCount
End Function
Private Sub IsgGridDataSource_GetRowData _
(ByVal RowIndex As Long, ByVal ColCount As Long, _
RowData As Variant)
Dim i As Integer
For i = 0 To ColCount - 1
RowData(i) = 0
Next
If arData(RowIndex) > 0 Then
RowData(1) = arData(RowIndex)
Else
RowData(0) = arData(RowIndex)
End If
End Sub
Private Sub IsgGridDataSource_SetRowData _
(ByVal RowIndex As Long, ByVal ColCount As Long, _
ByVal RowData As Variant)
If RowData(0) <> 0 Then
arData(RowIndex) = Val(RowData(0))
Else
arData(RowIndex) = Val(RowData(1))
End If
'invoke the GetRowData function
SGGrid1.RefetchRow Clng(SGGrid1.CurrentCell.RowKey)
End Sub
Private Function IsgGridDataSource_AddRow _
(ByVal RowIndex As Long, ByVal ColCount As Long, _
ByVal RowData As Variant) As Boolean
mlRowsCount = mlRowsCount + 1
If mlRowsCount > UBound(arData) Then
ReDim Preserve arData(mlRowsCount + 10) As Long
End If
If RowData(0) <> 0 Then
arData(mlRowsCount - 1) = Val(RowData(0))
Else
arData(mlRowsCount - 1) = Val(RowData(1))
End If
'if you are ready to add
'row set the AddRow to true
IsgGridDataSource_AddRow = True
End Function
Private Function IsgGridDataSource_DeleteRow _
(ByVal RowIndex As Long) As Boolean
Dim i As Integer
mlRowsCount = mlRowsCount - 1
'just move values for one place
For i = RowIndex To mlRowsCount - 1
arData(i) = arData(i + 1)
Next
'row will not be deleted if you dont
'set the DeleteRow to True
IsgGridDataSource_DeleteRow = True
End Function
See Also