Click here to Skip to main content
15,886,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi to All,

I am using Visual Studio 2010 with Sql server Express Edition 2005 as backend DB. I've a form with DataGridView with following columns:

OrderID ProductID UnitPrice Quantity Total

DataGridView is bind to Dataset Table, "Total" is a Calculated column which I've added using following code:

C#
column = new DataColumn();
column.DataType = Type.GetType("System.Double");
column.ColumnName = "Total";
ds.Tables[0].Columns.Add(column);
ds.Tables[0].Columns["Total"].Expression = "UnitPrice * Quantity";


Code works fine, it calculate the Total by multiplying UnitPrice to Quantity. The problem is this calculation is made when I move to new row. What I need is to it calculate Total when there is any change in UnitPrice or Quantity.

Is it possible? Any ideas/suggestions will be highly appreciated.

Regards

Ahmed
Posted
Comments
gondwe 10-Oct-14 12:28pm    
Having the same problem here. Im working on VS2013 application in vb.net bound to msaccess database. im looking for any help on the same as im new to this.

1 solution

Use one of DataGrigViewCell's method[^], for example OnLeave, and force datatable to re-calculate Total using Compute method[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900