14,695,615 members
1.00/5 (1 vote)
See more:
hi,

i want to multiply two numbers one by one until last row in datagridview;
and add them in a double variable . They then divided by the total units do.
for ex:
mark |units
12.00 * 2 = 24.00
20.00 * 3 = 60.00
15.00 * 1 = 15.00

24+60+15 = 59
59 / 2 + 3 + 1
= 59 /6
= 16.50

so show in a textbox.

Posted
jaideepsinh 3-Jul-13 4:00am

Paste you code here.

## Solution 1

```for (int i = 0; i <= dataGridView1.RowCount ; i++)
{
mark = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
unit  = Convert.ToInt32(dataGridView1.CurrentRow.Cells[2].Value);
result += ( s1 * s);

} ```

but this code calculate just first row.
how i change row index?

## Solution 2

i solve it!
```for (int i = 0; i < dataGridView1.RowCount ; i++)
{
mark = Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value);
unit = Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value);
sumunit += unit;
result += ( mark * unit);

}
result /= sumunit;
label2.Text = result.ToString();

}```
Naz_Firdouse 3-Jul-13 5:29am

Top Experts
Last 24hrsThis month
 OriginalGriff 250 RickZeeland 120 Rick York 100 Richard Deeming 100 Sandeep Mewara 100
 OriginalGriff 6,079 Richard Deeming 3,165 Richard MacCutchan 2,824 CPallini 2,012 Patrice T 1,650

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900