Click here to Skip to main content
15,891,902 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to calculate the data columns of row
and show the value into text box
like Amount=10
Amount=10
Amount=10
Amount=10
and i want to show into text box
i m trying this code but is sowing the last value of rows.
C#
double Final = 0;
                      //decimal Serial = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value);
                      decimal Quantity = Convert.ToDecimal(dataGridView1.Rows[i].Cells[2].Value);
                      decimal Rate = Convert.ToDecimal(dataGridView1.Rows[i].Cells[3].Value);
                      decimal vat = Convert.ToDecimal(dataGridView1.Rows[i].Cells[4].Value);

                      decimal TotalPrice = Convert.ToInt32(Quantity * Rate);

                      decimal TempVatTax = TotalPrice * Convert.ToDecimal(dataGridView1.Rows[i].Cells[4].Value) / 100;

                      TotalPrice = TempVatTax + TotalPrice;
                      dataGridView1.Rows[i].Cells[5].Value = TotalPrice;


                      Final = Convert.ToDouble(TotalPrice);
                      //Final=Convert.ToDouble(txt_Total.Text+Final);
                      //Final += CInt(row.Cells(0).Text);

                      txt_Total.Text = Convert.ToString(Final);

              }



Please Tell me the solution
Posted

I assume you are using this in a loop, from the Rows[i] stuff? If so, then if you want Final to be a cumulative total, then replace "=" with "+=":
C#
Final = Convert.ToDouble(TotalPrice);
Becomes
C#
Final += Convert.ToDouble(TotalPrice);
 
Share this answer
 
its calculating the current cell and show double value in text box
 
Share this answer
 
C#
double LastTotal=0;
           double Final = 0;
                     //decimal Serial = Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value);
                     decimal Quantity = Convert.ToDecimal(dataGridView1.Rows[i].Cells[0].Value);
                     decimal Rate = Convert.ToDecimal(dataGridView1.Rows[i].Cells[1].Value);
                     decimal vat = Convert.ToDecimal(dataGridView1.Rows[i].Cells[2].Value);

                     decimal TotalPrice = Convert.ToInt32(Quantity * Rate);

                     decimal TempVatTax = TotalPrice * Convert.ToDecimal(dataGridView1.Rows[i].Cells[3].Value) / 100;

                     TotalPrice = TempVatTax  + TotalPrice;

                     dataGridView1.Rows[i].Cells[4].Value = TotalPrice;


                     Final = Convert.ToDouble(TotalPrice);
           //Add this Code to your COde Editor
                     if (txt_Total.Text != "")
                     {
                         LastTotal = Convert.ToDouble(txt_Total.Text);
                     }
                     txt_Total.Text = Convert.ToString(Final+LastTotal);
 
Share this answer
 
ITS WORKING BUT ITS WORKING ONLY WORKING ONLY ONE TIME IF I CLICK ONE TIME ON BUTTON I WANT CALCULATION ON CELL LEAVE.

IF I CLICK ON BUTTON AND AGAIN I CLICK ON BUTTON CALCULATION NOT ACCURATE I DOING DOUBLE OF RECORD
 
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