Emma Emma

Emma Emma

  • NA
  • 101
  • 55.5k

C# datagridview two column multiple each other

Jun 28 2013 5:02 AM
  Hi,

I have one problem when I am trying to multiply two column's value with each other.Here is how it looks like:

-----Value-------Amplifier
-----30222-----0.002
------22222-----0.004
------0-----------0.01


what I want is Column of Value multiply Amplifer and store the result in Value column.
Here is my code:


for
(int n = 0; n < (dataGridView1.Rows.Count-1); n++)
{
double i=Convert.ToDouble(dataGridView1.Rows[n].Cells["Value"].Value.ToString());
double j=Convert.ToDouble(dataGridView1.Rows[n].Cells["Amplifier"].Value.ToString());
dataGridView1.Rows[n].Cells["Value"].Value=
Convert.ToString(i*j);
}

But I get one error in Here:

double j=Convert.ToDouble(dataGridView1.Rows[n].Cells["Amplifier"].Value.ToString());
which said : Input string was not in a correct format.
can anyone help me out with this...Thanks a lot

Answers (19)