Sub loaddata(sqlselstr As String)
'根据传递的sql,加载数据到MSHFlexGrid,并按要求显示所要的颜色
dim i as long,irow as long
dim rst as new adodb.recordset
With MSHFlexGrid
Screen.MousePointer = 11
rst.Open sqlselstr, dbconn, adOpenKeyset, adLockReadOnly
If rst.EOF = False Then
.Clear
Call loadlitte '加载标题
Prg.Visible = True '显示进度条
Me.Refresh
Prg.Max = 100 '显示进度条
Prg.Value = 0
.Rows = rst.RecordCount + 1
irow = 1
Do While Not rst.EOF
If rst(5) = "A" Then '设定改变单元格颜色的条件
.row = irow
For i = 0 To 17
.col = i '指定列
.CellForeColor = vbBlue '对列指定颜色
.TextMatrix(irow, i) = rst(i) & ""
Next
Else
.row = irow
For i = 0 To 17
.col = i '指定列
.CellForeColor = vbBlack '对列指定颜色
.TextMatrix(irow, i) = rst(i) & ""
Next
End If
Prg.Value = Prg.Value + 1
If Prg.Value >= 100 Then
Prg.Value = 0
End If
irow = irow + 1
rst.MoveNext
Loop
Else
MsgBox "没有找到所要的数据!", vbInformation, "提示..."
rst.Close
Set rst = Nothing
Screen.MousePointer = 0
Exit Sub
End If
For irow = 0 To .Rows - 1
.row = irow
For i = 0 To .Cols - 1
.col = i
If i = 2 Then
Else
.CellAlignment = flexAlignCenterCenter '数据居中
End If
Next
Prg.Value = Prg.Value + 1
If Prg.Value >= 100 Then
Prg.Value = 0
End If
Next
Prg.Visible = False
rst.Close
Set rst = Nothing
Screen.MousePointer = 0
End With
End Sub
本文介绍了一个使用 MS HFlexGrid 控件的过程,该过程通过 SQL 查询从数据库加载数据,并根据特定条件为单元格设置不同的颜色。此外,文章还展示了如何利用进度条来跟踪数据加载进度。
6141





