2

我有大约 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 秒,无论如何我可以让它更快

4

1 回答 1

4

sGrid的文档说“如果您可以按顺序添加行,您可以选择让 SGrid 为您预先分配一些行,而不是单独添加每一行,这可以提高性能。为此,请设置 Rows 属性到你想要的行数。”

于 2013-02-16T04:29:16.017 回答