home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 25: Programming / pc_actual_25.iso / Basic / GridOne / setup.EXE / CGRIDDATASOURCE.CLS < prev    next >
Encoding:
Visual Basic class definition  |  2001-09-09  |  5.3 KB  |  163 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "CGridDataSource"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. '-----------------------------------------------------------------------------
  15. ' This is a part of the BeeGrid ActiveX control.
  16. ' Copyright ⌐ 2000 Stinga
  17. ' All rights reserved.
  18. '
  19. ' You have a right to use and distribute the BeeGrid sample files in original
  20. ' form or modified, provided that you agree that Stinga has no warranty,
  21. ' obligations, or liability for any sample application files.
  22. '-----------------------------------------------------------------------------
  23. Option Explicit
  24.  
  25. Implements IsgGridDataSource
  26.  
  27. ' Array that is used as a data store
  28. Private Const maxRowCount = 110
  29. Public mRowCount As Long
  30. Private mColCount As Long
  31. Private arrData() As String
  32.  
  33.  
  34. Private Sub Class_Initialize()
  35.  
  36.    ' Initialize data array
  37.    mRowCount = 64
  38.    mColCount = 6
  39.    ReDim arrData(0 To maxRowCount - 1, 0 To mColCount - 1)
  40.    Dim i As Long
  41.    For i = 0 To mRowCount - 1
  42.       arrData(i, 0) = i
  43.       arrData(i, 1) = i Mod 8
  44.    Next
  45. End Sub
  46.  
  47. '------------------------------------------------------------------------------
  48. ' IsgGridDataSource implementation
  49. '------------------------------------------------------------------------------
  50. Private Function IsgGridDataSource_AddRow(ByVal RowIndex As Long, _
  51.                                           ByVal ColCount As Long, _
  52.                                           ByVal RowData As Variant) As Boolean
  53.  
  54.    ' The AddRow function is called by the BeeGrid control when it needs to
  55.    ' add a new row to the data source. This function should return True
  56.    ' if the new row has been added to the data store.
  57.    '
  58.    ' Parameters:
  59.    '    RowIndex - not used in this version
  60.    '    ColCount - number of elements in the RowData array
  61.    '    RowData  - array of variants with row data
  62.    
  63.    If mRowCount < maxRowCount Then
  64.       ' Add new row
  65.       mRowCount = mRowCount + 1
  66.       
  67.       ' Copy given data to the internal buffer
  68.       Dim col As Long
  69.       For col = 0 To ColCount - 1
  70.          arrData(mRowCount - 1, col) = RowData(col)
  71.       Next
  72.       
  73.       ' Row has been added
  74.       IsgGridDataSource_AddRow = True
  75.    Else
  76.       ' Row limit is reached
  77.       IsgGridDataSource_AddRow = False
  78.    End If
  79. End Function
  80.  
  81. Private Function IsgGridDataSource_DeleteRow(ByVal RowIndex As Long) As Boolean
  82.  
  83.    ' The DeleteRow function is called by the BeeGrid control when it needs
  84.    ' to delete a row from the data source. This function should return True
  85.    ' if a row has been deleted from to the data store.
  86.    '
  87.    ' Parameters:
  88.    '    RowIndex - data index of the row to be deleted
  89.    
  90.    If (RowIndex >= 0) And (RowIndex < mRowCount) Then
  91.    
  92.       ' Shift rows below deleted one
  93.       Dim row As Long, col As Long
  94.       For row = RowIndex + 1 To mRowCount - 1
  95.          Dim colUBound
  96.          colUBound = UBound(arrData, 2)
  97.          For col = 0 To colUBound
  98.             arrData(row - 1, col) = arrData(row, col)
  99.          Next
  100.       Next
  101.       
  102.       ' Decrese row count
  103.       mRowCount = mRowCount - 1
  104.       
  105.       ' Row has been deleted
  106.       IsgGridDataSource_DeleteRow = True
  107.    Else
  108.       ' Can not delete any more rows
  109.       IsgGridDataSource_DeleteRow = False
  110.    End If
  111. End Function
  112.  
  113. Private Function IsgGridDataSource_GetRowCount() As Long
  114.    
  115.    ' The GetRowCount function is called by the BeeGrid control when it needs
  116.    ' to know exact row count. This function should return current row count.
  117.    
  118.    IsgGridDataSource_GetRowCount = mRowCount
  119.    Debug.Print mRowCount
  120. End Function
  121.  
  122. Private Sub IsgGridDataSource_GetRowData(ByVal RowIndex As Long, _
  123.                                          ByVal ColCount As Long, _
  124.                                          RowData As Variant)
  125.  
  126.    ' The GetRowData subroutine is called by the BeeGrid control when it
  127.    ' needs data from a particular row. This function should initialize
  128.    ' RowData parameter with array of variants. Each variant in that
  129.    ' array represents data for one row cell.
  130.    '
  131.    ' Parameters:
  132.    '    RowIndex - index of the requested row
  133.    '    ColCount - number of elements in the RowData array
  134.    '    RowData  - array of variants with row data. This array
  135.    '               has ColCount elements and is resized by the
  136.    '               caller (BeeGrid control).
  137.    
  138.    Dim col&
  139.    For col = 0 To ColCount - 1
  140.       RowData(col) = arrData(RowIndex, col)
  141.    Next
  142. End Sub
  143.  
  144. Private Sub IsgGridDataSource_SetRowData(ByVal RowIndex As Long, _
  145.                                          ByVal ColCount As Long, _
  146.                                          ByVal RowData As Variant)
  147.                                          
  148.    ' The SetRowData subroutine is called by the BeeGrid control when it
  149.    ' needs to update row data.
  150.    '
  151.    ' Parameters:
  152.    '    RowIndex - index of the row that is being updated
  153.    '    ColCount - number of elements in the RowData array
  154.    '    RowData  - array of variants with row data.
  155.    
  156.    Dim col&
  157.    For col = 0 To ColCount - 1
  158.       arrData(RowIndex, col) = RowData(col)
  159.    Next
  160. End Sub
  161.  
  162.  
  163.