Link to home
Start Free TrialLog in
Avatar of feesu
feesu

asked on

VB.NET WinForms - DataGridView - Adding new rows, removing old ones to AcceptChanges

Hi Experts,

I am using the following to refresh my dataGridView. Instead of rebinding i need to add only new items into the datatable and remove the old ones. It adds the new rows, but fails to remove the old ones!



            '--------------------------------------------------------------------------------------------
            ' Start                                                                               New Row
            '--------------------------------------------------------------------------------------------
            'Dim newDT As DataTable = db.Feed_KSE_KARS_Quotes_GetNew(2, 0, Me.Label1.Text).Tables(0)
            'Dim newRow As DataRow
            'For Each newRow In newDT.Rows

            '    If Not newRow("row") Is DBNull.Value Then

            '        Dim currentRow As DataRow = DT.NewRow
            '        Dim i As Integer

            '        Dim dv As New DataView(DT)
            '        dv.RowFilter = "Row= " & newRow("row")
            '        DT.Rows.Remove(dv.Table.Rows(0))

            '        For i = 0 To newRow.ItemArray.Length - 1
            '            currentRow(i) = newRow(i)
            '        Next
            '        DT.Rows.Add(currentRow)

            '        'DT.Select("Row=" & newRow("Row"))
            '        'DT.PrimaryKey = col
            '        'DT.Rows.Remove(DT.Rows.Find(newRow("Row")))

            '    End If
            'Next

            'DT.AcceptChanges()
            '--------------------------------------------------------------------------------------------
            ' End                                                                                 New Row
            '--------------------------------------------------------------------------------------------
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

I would imagine that is because this won't work:

      DT.Rows.Find(newRow("Row"))

Bob

Avatar of feesu
feesu

ASKER

Any alternative code to fix my bug Bob?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forced accept.

Computer101
EE Admin