Populating two sgrids faster

259 Views Asked by At

I have about 10K records each that i have to populate in two vbaccelerators sgrids, i currently use the following code

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

The additem subroutine is different for the two grids, peculiar to the data being pupulates. it looks like this

    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

it takes about 20 seconds to fill the grids, is there anyway i can make this faster

1

There are 1 best solutions below

3
Joel Spolsky On BEST ANSWER

The documentation for sGrid says "If you can add rows in order, you can choose to have SGrid pre-allocate a number of rows for you, rather than adding each one individually, which can improve performance. To do this, set the Rows property to the number of rows that you want."