Link to home
Start Free TrialLog in
Avatar of tobin46
tobin46

asked on

Compute Method in DataTable

I have a DataTable, bound to a DataGridView for data entry.  As a row is entered, I'd like to populate a label with the running total of the "Total Cost" column.  

I've found documentation and have code that is working, BUT, it seems that the compute method is always one row behind.  User enters row(0), the label does not populate, then after user enters rows(2), going into Row(3), the label.text is populated with the total of Row(0) only.

When I call DataTable.AcceptChanges, the datatable is cleared.  

Any thoughts?

Here is code I'm using:

Private Sub DG_Labor_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DG_Labor.CellValueChanged
    If e.ColumnIndex = 9 Then
                    Try
                        Me.Calc_Labor_Totals()
                    Catch ex As Exception
                        MsgBox("Couldn't Calculate the total Labor Sum")
                    End Try
    End If
End Sub

Private Sub Calc_Labor_Totals()
        Dim result = dt_LaborInfo.Compute("sum(Labor_Total_Cost)", "")
        Me.lbl_Labor_Totals.Text = result.ToString()
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of Carlos Villegas
Carlos Villegas
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
Avatar of tobin46
tobin46

ASKER

Perfect.  Worked great!
Glad to help buddy!