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


Reply With Quote