calculated column

vortex

Member
Joined
Jul 1, 2005
Messages
8
Programming Experience
Beginner
calculated column [resolved]

Is there a way to calculate a value for a column, e.g. col3 = col1 + col2, without a computed column using expressions.



Maybe programmatically calculating the column when the user adds a new row.



Ive tried adding a event handler on rowschanged but with no luck.
 
Last edited:
Sum columns of the dataset

Dim sumTotalOrdered As Integer
Dim sumTotalOnHand As Integer

sumTotalOrdered = DsShipperDeliveries1.Tables(0).Compute("Sum(Quantity)", String.Empty)
lblTotalOrdered.Text = sumTotalOrdered
sumTotalOnHand = DsShipperShopNumber1.Tables(0).Compute("Sum(Qty)", String.Empty)
lblTotalOnHand.Text = sumTotalOnHand

You will have to add code to add values when rows are added but this will give you the starting totals.
 
DavidT_macktool said:
Dim sumTotalOrdered As Integer
Dim sumTotalOnHand As Integer

sumTotalOrdered = DsShipperDeliveries1.Tables(0).Compute("Sum(Quantity)", String.Empty)
lblTotalOrdered.Text = sumTotalOrdered
sumTotalOnHand = DsShipperShopNumber1.Tables(0).Compute("Sum(Qty)", String.Empty)
lblTotalOnHand.Text = sumTotalOnHand

I dont need totals for the columns, i need totals for each row.


DavidT_macktool said:
You will have to add code to add values when rows are added but this will give you the starting totals.

Can you please provide some examples codes.

many thanks
 
This is what my attempt at calculating the row total looks like, unfortunately it doesn’t work, the program loops until i get a stack overflow error, any suggestions to fix this or I’m I barking up the wrong tree?


VB.NET:
 Private Sub Row_Changed(ByVal sender As Object, ByVal e As DataRowChangeEventArgs)[/color]
 
[color=black]Dim temp_total As Double = 0 [/color]
 
[color=black]temp_total = e.Row("price", DataRowVersion.Current) * e.Row("qty", DataRowVersion.Current)[/color]
 
[color=black]e.Row("Total") = temp_total [/color] 
[color=black]End If
 
Back
Top