Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

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

Avatar of feesu
feesu asked on
.NET ProgrammingVisual Basic.NET
4 Comments1 Solution6591 ViewsLast Modified:
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
            '--------------------------------------------------------------------------------------------