Fastest way for insert rows

Originally Posted 1 September 2011, 9:21 am EST

  • Originally Posted 1 September 2011, 9:21 am EST

    Hello,
    which is the fastest way for inserting rows/filling-up a grid?

    For example using a simple

        Dim starttimer As Long
    Dim i As Long

    starttimer = Timer
    grid1.Redraw = False
    grid1.Cols = 2
    grid1.Rows = 2
    For i = 1 To 20000
    grid1.Rows = grid1.Rows + 1
    grid1.Row = grid1.Rows - 2

    grid1.TextMatrix(grid1.Row, 1) = "Row " & i
    Next
    grid1.Redraw = True
    Label1.Caption = "Elapsed " & (Timer - starttimer) & " secs"


    is a lot slower (20 seconds against 2 seconds) than using

        Dim starttimer As Long
    Dim i As Long

    starttimer = Timer
    grid1.Redraw = False

    grid1.Rows = 2
    grid1.Cols = 2
    For i = 1 To 20000
    grid1.Rows = grid1.Rows + 1
    grid1.Row = grid1.Rows - 2
    grid1.TextMatrix(grid1.Row, 1) = "Row " & i

    If (i Mod 500) = 0 Then
    grid1.Redraw = True
    grid1.ShowCell grid1.Row, grid1.Col
    grid1.Refresh
    grid1.Redraw = False
    End If

    Next
    grid1.Redraw = True
    Label1.Caption = "Elapsed " & (Timer - starttimer) & " secs"


    There is a fastest way or something i can do to futher optimize it?
    I'm using VsFlexGrid 8.

    Thanks
  • Reply

    Hi,,

    There is no fastest recommended way to do the same, as such it depends upon the way you are implementing the same, on the code optimization you can do on your end

    For e.g in your second code you have made grid1.Redraw = False while you are adding the rows and data, thus it saves time as the grid need not needs to repaint itself on every row add and it gets updated/painted in the end of the whole process

    So in all it depends on what type of implementation you are doing on your end

    You may use the latest build for better results


    http://prerelease.componentone.com/activex/C1FlexGrid/C1FlexGrid%208.0/2011-T2/vsflex8_8.0.20112.285.zip


    Regards
    ~Gatim--
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels