Reputation: 1571
I have a DataGridView
which is using a DataTable
as the source (dtOrders
) in my project. I'm trying to update dtOrders
with an edited row and have the DataGridView
display the updated row. I'm using the following code that is called from a BackGroundWorker
(bgwWriteToDatabase
)
Public r as ArrayList = New ArrayList
Private Sub UpdateOrderTable()
Try
r.Add(RowNum)
r.Add(bwOrderID)
r.Add(bwClientID)
r.Add(bwMaterials)
r.Add(bwInstaller)
r.Add(bwMaterialsCost)
r.Add(bwInstallerCost)
r.Add(bwElectricalCosts)
r.Add(bwPipeFittingCosts)
r.Add(bwSundriesCosts)
r.Add(bwTotalCost)
r.Add(bwNotes)
dtOrders.Rows(r(0))("ID") = r(1)
dtOrders.Rows(r(0))("ClientRef") = r(2)
dtOrders.Rows(r(0))("Materials") = r(3)
dtOrders.Rows(r(0))("Installer") = r(4)
dtOrders.Rows(r(0))("MaterialsCost") = r(5)
dtOrders.Rows(r(0))("InstallersCosts") = r(6)
dtOrders.Rows(r(0))("ElectricalWork") = r(7)
dtOrders.Rows(r(0))("PipeFittingValves") = r(8)
dtOrders.Rows(r(0))("Sundries") = r(9)
dtOrders.Rows(r(0))("TotalCosts") = r(10)
dtOrders.Rows(r(0))("Notes") = r(11)
bgwWriteToDatabase.ReportProgress(10, 10)
Catch ex As Exception
Debug.Print(ex.Message.ToString)
Errorbits(3) = True
End Try
End Sub
Private Sub bgwWriteToDatabase_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles bgwWriteToDatabase.ProgressChanged
If e.ProgressPercentage = 10 Then
dgvViewOrders.DataSource = dtOrders
End If
End Sub
The code is executed whenever the Submit button is pressed on the form. The first time the code runs, the DataGridView
updates perfectly, it displays the new information correctly and everything seems fine.
The second time the Submit button is pressed, the information is not updated on the DataGridView
. I'm having a hard time understanding why it works the first time, but not the second.
I have debugged and the code runs with no errors on the first run and no errors on the second run, the BackGroundWorker
executes in the same way on both cycles but doesn't produce the update on the second time round.
Am I missing something obvious here?
Upvotes: 0
Views: 209