title: how do i total the sum from datagridview vb.net
body: <p>-how do i get the sum of totalPrice in my datagridview from mysql</p>
  
  <pre><code>ProductName          Qty.   Price    totalPrice
  2 Pcs. Chickenjoy     5      59         295
  2 Pcs. Chickenjoy     1      69          69
  2 Pcs. Chickenjoy     1      69          59
  
                                    TOTAL??
  </code></pre>
  
  <p>-the sum should be 423 the problem is,  it will double the sum</p>
  
  <p>-here's my code:</p>
  
  <pre><code>Try
      'declaring variable as integer to store the value of the total rows in the datagridview
  
      Dim max As Integer = DataGridView1.Rows.Count - 1
      Dim total As String = "Total -----------&gt;"
      'getting the values of a specific rows
  
  
      For Each row As DataGridViewRow In DataGridView1.Rows
          'formula for adding the values in the rows
          DataGridView1.Rows(max).Cells(4).Value += row.Cells(4).Value
          DataGridView1.Rows(max).Cells(3).Value = total
      Next
  Catch ex As Exception
      MsgBox(ex.Message)
  End Try
  </code></pre>
  
  <p>Screenshots
  <a href="http://goo.gl/Ufj53b" rel="nofollow">http://goo.gl/Ufj53b</a></p>