First off, why are you doing that?
If you already have the row, why are you using it's row index to fetch it again, repeatedly?
foreach (DataGridViewRow row in dataGridView1.Rows)
{
row.Cells[4].Value = Double.Parse(row.Cells[3].Value.ToString()) - Double.Parse(row.Cells[1].Value.ToString());
}
is the same, but more readable (and efficient)
Now you need to look at the data and find which of these is null: we can;t do that for you, and the chances are that one or more of your cells contains a
null
value - so when you do
row.Cells[n].Value
it tries to call the Value parameter of the non-existent value and you get an exception.
We don't have your data - so we can't tell. So use the debugger, and start looking at what row and column is causing the problem!