我有大约10K记录,每个我必须填充两个vbaccelerators sgrids,我目前使用以下代码
With grdList
.Clear
If colTasks Is Nothing Then Exit Sub
.ReDraw = False
For i = 1 To colTasks.Count
AddItem colTasks(i)
Next
.ReDraw = True
End With
additem子程序对于两个网格是不同的,这些数据是傀儡数据所特有的。看起来像这样
Dim lCol As Long
Dim bIsDue As Boolean
Dim sCat As String
sCat = cboCat.Text
With grdList
If IsEqual(sCat, oItem.Category) Or IsEqual(sCat, "all") Then
' Show/Remove Completed
If Not IsNullOrEmpty(oItem.DueDate) Then
sCat = DateDiff("d", oItem.DueDate, DateValue(Now))
bIsDue = (CLng(sCat) > 0)
If ShowDueOnly And Not bIsDue Then Exit Function
End If
Else
Exit Function
End If
If lRow > .Rows Or lRow = 0 Then
grdList.AddRow
lRow = .Rows
End If
If Not IsNullOrEmpty(oItem.DueDate) Then
lCol = .ColumnIndex("DueDate")
lColor = IIf(bIsDue, vbRed, vbBlack)
sCat = Format$(oItem.DueDate, "MM/dd/yyyy")
.CellDetails lRow, lCol, CDate(sCat), DT_LEFT, IconIndex("ARROW"), , lColor
End If
lCol = .ColumnIndex("Privacy")
.CellIcon(lRow, lCol) = IIf(oItem.IsPrivate, IconIndex("LOCK"), -1)
'completed
lCol = .ColumnIndex("Complete")
.CellIcon(lRow, lCol) = IIf(oItem.Completed, IconIndex("CHECK"), -1)
End With
填充网格大约需要20秒,无论如何我可以加快这个速度
答案 0 :(得分:4)
documentation for sGrid说“如果你可以按顺序添加行,你可以选择让SGrid为你预先分配一些行,而不是单独添加每行,这样可以提高性能。 ,将Rows属性设置为您想要的行数。“