14,733,039 members
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.
```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);

}```

Posted

## Solution 1

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 "+=":
`Final = Convert.ToDouble(TotalPrice);`
Becomes
`Final += Convert.ToDouble(TotalPrice);`

## Solution 2

its calculating the current cell and show double value in text box

## Solution 3

```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);
if (txt_Total.Text != "")
{
LastTotal = Convert.ToDouble(txt_Total.Text);
}
txt_Total.Text = Convert.ToString(Final+LastTotal);```

## Solution 4

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