0

I know that here are quite a few similar questions to this one, but some of them are in VB or the answer does not work for my code. So here it is:

 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {


        if(e.ColumnIndex == 7)
        {

            double cellvalue = new double();
            double totalkcal = new double();
            double totalpret = new double();


            double.TryParse(dataGridView1[e.ColumnIndex - 1, e.RowIndex].Value.ToString(), out cellvalue);
            double.TryParse(dataGridView1[e.ColumnIndex - 3, e.RowIndex].Value.ToString(), out totalkcal);
            double.TryParse(dataGridView1[e.ColumnIndex - 4, e.RowIndex].Value.ToString(), out totalpret);

            textBox5.Text = totalkcal.ToString();


        }
    }

What's wrong with it? I get the error in the title whenever the cell is clicked.

Thanks a lot !

Alex Kayz
  • 189
  • 1
  • 11

1 Answers1

-4

Give initial values to variables:

double cellvalue = 0;
double totalkcal = 0;
double totalpret = 0;
Orkun Bekar
  • 1,349
  • 1
  • 12
  • 34