Click here to Skip to main content
14,695,615 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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.

please help me.
Posted
Comments
jaideepsinh 3-Jul-13 4:00am
   
Paste you code here.

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?
   
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();

}
   
Comments
Naz_Firdouse 3-Jul-13 5:29am
   
gr8...u solved your own question and thanks for posting your answer which will be helpful for others

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




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