Reputation: 465
I have a strongly typed data set that contains a readonly
column calculated by its expression property. The calculated column is a totalAmountDue
and the expression is ( totalAmountBilledColumn - totalAmountPaidColumn )
. The problem is I can't get the calculated column to re-evaluate when either of the two calculating columns are changed.
Does anyone know how to force the data set to re-evaluate columns with expressions?
Thanks.
Upvotes: 1
Views: 2831
Reputation: 2217
Just came across this. Funny thing about expressions is that they don't evaluate until row is added to table. Once a row is added to table, It will work. Here is an example.
DataTable table = new DataTable();
table.Columns.Add("debit", typeof (double)).DefaultValue = 0;
table.Columns.Add("credit", typeof(double)).DefaultValue = 0;
table.Columns.Add("net", typeof(double),"debit - credit");
DataRow row = table.NewRow();
Console.WriteLine("First: {0}",row["net"]); // won't work
row["debit"] = 500;
Console.WriteLine("Sec: {0}", row["net"]); // won't work
row["credit"] = 0;
Console.WriteLine("Thr: {0}", row["net"]); // won't work
table.Rows.Add(row);
Console.WriteLine(row["net"]); // works
Upvotes: 3