Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

I have one problem with datagridview. I want to multiplying two cells and display the result in third cell

example:
A     | B  |  C
10.50 | 2  | 21,00
5.20  | 4  | 20,80
7,3   | 5  | 36,50


after that i wanna to sum C column and display that in textBox.
Column A is type decimal
Column B is integer
Column C should be decimal too

how to do that and how to display decimal value in textbox?

This is what I have trie
C#
foreach (DataGridViewRow item in dataGridView1.Rows)
{
  int n = item.Index;
  dataGridView1.Rows[n].Cells[2].Value = 
      (Double.Parse(dataGridView1.Rows[n].Cells[0].Value.ToString()) +
      Double.Parse(dataGridView1.Rows[n].Cells[1].Value.ToString())).ToString();
}

textBox1.Text = "0";
foreach (DataGridViewRow item in dataGridView1.Rows)
{
  int n = item.Index;
  textBox1.Text = (Double.Parse(textBox1.Text.ToString()) +     
          Double.Parse(dataGridView1.Rows[n].Cells[2].Value.ToString())).ToString();
}
this code should sum cells, but i want to multiplying cells. i was trying to do anything!
Posted
Updated 1-Jun-13 0:53am
v3
Comments
Please post what have you tried so far ?

1 solution

 
Share this answer
 

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