应用心得
1)MSHFlexGrid控件与MSFlexGrid控件的异同
MSHFlexGrid控件与Adodc控件绑定,MSFlexGrid控件与Data控件绑定。
2)MSHFlexGrid控件的应用
如果记录集已经在程序中产生,则可以不与Adodc控件绑定,直接在MSHFlexGrid控件中显示数据,并且可以根据需要设置控件中行的颜色,如下例:
Public Function DataGrid_Update() As Boolean
On Error GoTo DataGrid_Update_Err
Dim orarsRecordset As Object
Dim adorsRecordset As New ADODB.Recordset
Dim lngDateDiff As Long
Call gGetData(CONST_GENERALTABLE_TIMEOUT_INFO, orarsRecordset)
If Not ADO_DataBaseOpen(dskAttr, 1) Then
DataGrid_Update = False
Exit Function
End If
adorsRecordset.CursorLocation = adUseClient
Call adorsRecordset.Open(CONST_VEHICLETABLE_RECORDSET_QUERIED, _
mobjDataSource.ConnectionString, , , adCmdText)
frmShowNewData.grdSaiShin.ColWidth(0) = 800
frmShowNewData.grdSaiShin.ColWidth(1) = 2000
frmShowNewData.grdSaiShin.AllowUserResizing = flexResizeColumns
Set frmShowNewData.grdSaiShin.DataSource = adorsRecordset
Dim i As Integer
i = 0
i = i + 1
While Not adorsRecordset.EOF
lngDateDiff = DateDiff("n", adorsRecordset.Fields("測位日時"), Now)
If lngDateDiff > orarsRecordset.Fields("GEN_V_NUM").Value Then
frmShowNewData.grdSaiShin.Row = i
Dim j As Integer
For j = 0 To frmShowNewData.grdSaiShin.Cols - 1
frmShowNewData.grdSaiShin.Col = j
frmShowNewData.grdSaiShin.CellBackColor = &H80FFFF
Next
End If
i = i + 1
adorsRecordset.MoveNext
Wend
Call ADO_DataBaseClose
DataGrid_Update = True
Exit Function
DataGrid_Update_Err:
Call ADO_DataBaseClose
DataGrid_Update = False
End Function