title: Multiplying data in 2 datagridview columns
body: <p>I have been looking around the internet for some useful guide, but I have found non - How can I multiple two numbers in row, remember that value and then do the same for the rest of rows in datagridview and all those values sum together. And the total summary display in <code>textbox</code>. Those two columns are displayed using <code>SqlCommand</code> . But I would like to change the value in <code>textbox</code> every time there is made change in column <code>pocet</code> datagridview (when I do change in datagridview it doesnt insert the values into SQL).  So I didn't hesitate and I asked you in my previous question <a href="https://stackoverflow.com/questions/17759170/math-operation-with-datagridview-columns-row-by-row-then-display-final-value-in/17760539?noredirect=1#comment25901951_17760539">here</a> and user varocarbas - I'm so thankful for his time which he spent making it. </p>
  
  <p>He came up with this code:</p>
  
  <pre><code> void calculateProductTwoColumns(int castkaIndex, int pocetIndex, int tot_rows)
      {
          try
          {
              double[] outVals = new double[tot_rows + 1]; 
              int curRow = 0;
              foreach (DataGridViewRow row in dtg_ksluzby.Rows)
              {
                  curRow = curRow + 1;
                  outVals[curRow] = (double)row.Cells[castkaIndex].Value * (double)row.Cells[pocetIndex].Value;
  
                  kpriplac.Text = outVals.ToString();
              }
          }
          catch (Exception ex)
          {
              MessageBox.Show("" + ex.Message.ToString());
          }
  
  
      }
  </code></pre>
  
  <p>So I tried to "improve" it to make it work like I desire but I think I little messed it up. I would like to multiply in each row columns pocet(dgv index 3) and cena(dgv index 2). So I call this method like this:</p>
  
  <pre><code>  calculateProductTwoColumns(2, 3, 4);
  </code></pre>
  
  <p>When I start debugging it says: <code>Specified cast is not valid.</code> I tried to debug it with breakpoints but I couldn't find where I make mistake.</p>
  
  <p>pocet is int and castka is numeric numeric(15, 2)</p>
  
  <p>Thank you so much for your time reading this, I will be pleased with any comentary or reference to guides.</p>