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_Ge tNew(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.Ro ws(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.Fi nd(newRow( "Row")))
' End If
'Next
'DT.AcceptChanges()
'------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -------
' End New Row
'------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -------
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_Ge
'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.Ro
' 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.Fi
' End If
'Next
'DT.AcceptChanges()
'-------------------------
' End New Row
'-------------------------
ASKER
Any alternative code to fix my bug Bob?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
DT.Rows.Find(newRow("Row")
Bob