troubleshooting Question

How to calculate the sum of all rows at each new row in C#

Avatar of SniperCode Sheva
SniperCode Sheva asked on
C#* DataGridView
4 Comments1 Solution1439 ViewsLast Modified:
My app is a sort of cash register for a shop so in the datagrid there is Reference ,
it is the reference of the product.
When the user types the reference directly the information about the product will be filled in the other columns and the user can choose the quantity he wants and it will do the calculation.

ALSO, I tried to put the total of the bill in the datagrid...

Reference | Product |Quantity |Price |Total |Total Bill
AB              |AB           |2               |1000 |2000 |5000
BC              |BC            |3              |1000 |3000

This is what I am trying to do... To do it, I tried this code:

private void TAB_Credit_RowValidated(object sender, DataGridViewCellEventArgs e)
    int sum = 0;
    for (int i = 0; i < TAB_Credit.Rows.Count; ++i)
        sum += Convert.ToInt32(TAB_Credit.Rows[i].Cells["Total"].Value);
    TAB_Credit.Rows[e.RowIndex].Cells["Total_Bill"].Value = sum.ToString();
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 4 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros