That isn't an average - it's a sum. The average is calculated by summing the other rows and dividing the sum by the number of elements you added together.
In addition, that doesn't do anything particularly useful because it always sums the same row - including the location that you stick the result in each time - and the first set of lines before the
foreach
line do nothing at all ...
If you want to show an average for each row, then either use the
DataGridView.RowPrePaint Event[
^] or add a formula to your Excel file so it is calculated by the engine when the spreadsheet is accessed.
And you shouldn't be using and modifying Row values, you should be using and modifying the underlying data behind them in the DataSource directly.
To be honest, that looks like you threw it together in a hurry, and just hoped it would magically do what you wanted - and development does not work like that at all!