Results 1 to 2 of 2

Thread: DataGrid / DataTable Speed Question

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Michigan
    Posts
    304

    Unhappy DataGrid / DataTable Speed Question

    I have a speed issue when adding to a DataGrid. The first time I add about 200 rows it take < 1 second. The second time I add 200 rows it takes about 10 seconds. Why is this?

    I am wondering if I am not leaving the grid or table in a proper state the first time thru? Please help if you have any ideas - thanks.


    Here is the appropriate snippet of code:
    Code:
        Private Sub ButtonDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDisplay.Click
            Dim StartId As Int32 = CInt("&H" & TextBoxStartId.Text)
            Dim StopId As Int32 = CInt("&H" & TextBoxStopId.Text)
            Dim myRow As DataRow
    
            DataGrid1.Enabled = False
            dtMessage.BeginLoadData()
            DataGrid1.BeginInit()
            Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
    
            For i As Int32 = StartAddr To StopAddr Step StepSize
                myRow = dtMessage.NewRow()
    
                myRow(gMessageTime) = gAscFile(0).RxMsgs(i).Time
                myRow(gMessageChannel) = gAscFile(0).RxMsgs(i).Channel
                myRow(gMessageName) = gAscFile(0).RxMsgs(i).IdMsg
                myRow(gMessageId) = Hex(gAscFile(0).RxMsgs(i).Id)
                myRow(gDcl) = gAscFile(0).RxMsgs(i).Dlc
                myRow(gLine) = gAscFile(0).RxMsgs(i).Line
                myRow(gEcu) = gAscFile(0).RxMsgs(i).Transmitter
    
                Dim Mg As String = ""
                For j As Int16 = 0 To gAscFile(0).RxMsgs(i).Dlc - 1
                    If gAscFile(0).RxMsgs(i).Msg(j) < 16 Then
                        Mg += "0" & Hex(gAscFile(0).RxMsgs(i).Msg(j)) + "  "
                    Else
                        Mg += Hex(gAscFile(0).RxMsgs(i).Msg(j)) + "  "
                    End If
                Next
                myRow(gMessage) = Mg
    
                dtMessage.Rows.Add(myRow)
     
            Next
    
            dtMessage.EndLoadData()
    
            dtMessage.AcceptChanges()
            DataGrid1.EndInit()
    
            ButtonDisplay.Enabled = True
            ButtonSave.Enabled = True
            ButtonClear.Enabled = True
            ButtonRemove.Enabled = True
            ComboBoxChannel.Enabled = True
            DataGrid1.Enabled = True
            UpdateGridLines()
            Me.Enabled = True
            Cursor.Current = System.Windows.Forms.Cursors.Default
        End Sub

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Michigan
    Posts
    304

    Re: DataGrid / DataTable Speed Question

    SOLVED!!!!

    I created an empty data table and assigned that to the data grid. Then I add my new rows to the existing data table. When done adding the data newly modified data table back to the data grid.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width