MSHFlexGrid显示速度非常慢
Private Sub showcls() '显示MSHFlexGridDim HH As Integer
Dim I As Integer
HH = 1
With Grid1
.Clear
.BackColor = &HFFFFFF
.FormatString = "^ |^存货代码|^类别编码|^存货名称及规格|^结存数量|^结存金额"
.ColWidth(0) = 500
.ColWidth(1) = 1200
.ColWidth(2) = 1500
.ColWidth(3) = 4000
.ColWidth(4) = 1800
.ColWidth(5) = 2000
For I = 0 To 5
.ColAlignmentFixed(I) = 4
Next I
For I = 1 To 3
.ColAlignment = 1
Next I
For I = 4 To 5
.ColAlignment = 7
Next I
If rs.State <> adStateClosed Then
rs.Close
End If
rs.CursorLocation = adUseClient
'首先读取存货项目表
rs.Open "select * from ICItem order by FitemID", cn, adOpenKeyset, adLockPessimistic
If rs.RecordCount <> 0 Then
rs.MoveFirst
.Rows = rs.RecordCount + 1
Do Until rs.EOF
.Row = HH
.Col = 0
.Text = HH
.Col = 1
.Text = rs!FitemID
.CellBackColor = &HC0FFFF '定义第2、3、4列的背景色为黄色,为以后是否能编辑定义,黄色不能修改
.Col = 2
.Text = rs!LbCode
.CellBackColor = &HC0FFFF
.Col = 3
.Text = rs!FitemName & " " & rs!Fmodel
.CellBackColor = &HC0FFFF
.Col = 4
.Text = Format(rs!FBegQty, "#,##0.00")
.Col = 5
.Text = Format(rs!FBegBal, "#,##0.00")
HH = HH + 1
rs.MoveNext
Loop
If HH = .Rows Then
.Rows = HH + 1
End If
.TextMatrix(HH, 0) = HH
.TextMatrix(HH, 1) = "合 计"
If rssum.State <> adStateClosed Then
rssum.Close
End If
rssum.Open "select sum(FBegBal) from ICInitData where left(FClsID," & ijbcd & ")='" & Left(schlb, ijbcd) & "' and FStockID=" & ick & "", cn, adOpenKeyset, adLockPessimistic
.Col = 5
.Text = Format(rssum.Fields(0), "#,##0.00")
For I = 1 To 5
.Row = HH
.Col = I
.CellBackColor = &HC0FFFF '最后一行全为黄色,即单元格不能编辑
Next I
Else
.BackColor = &HC0FFFF
.Rows = rs.RecordCount + 2
End If
rs.Close
.ReDraw = False
.BackColorFixed = RGB(190, 218, 178) '定义固定表头的背景色
.ReDraw = True
End With
End Sub
这段代码执行下来的时候,记录少的话还可以,但是如果比较多的话,显示出来就非常慢(100条以内都慢),有没有能使显示速度快一点的办法!