The reason for getting the out of range error may be because the
DataGridView
Rows
collection is zero based whereas in the following code
c = (DataGridView1.Item(j + 3, r + 1).value * DataGridView1.Item(j + 2, r + 1).value)
r+1
for
upper bound value
of the loop makes
Row index
as
a
which causes the above error.
So replace
r+1
with
r
in the above code further it is better to convert the value to
Double
for multiplication as already suggested in
Solution 1
, as shown below:
c = Convert.ToDouble(DataGridView1.Item(j + 3, r + 1).value) * Convert.ToDouble(DataGridView1.Item(j + 2, r + 1).value)