1 Replies - 304 Views - Last Post: 10 February 2013 - 05:43 AM Rate Topic: -----

#1 SeMiC  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-May 12

Question about sum a column in dataGrip view

Posted 10 February 2013 - 05:27 AM

Hello
i'm trying to get the total of a Specific column
i've tried this code
Dim Profit As Integer = 0
        Dim counter As Integer
        For counter = 0 To (DataGridView1.Rows.Count - 1)
            If Not DataGridView1.Rows(counter).Cells("Amount").Value Is Nothing Then
                If Not DataGridView1.Rows(counter).Cells("Amount").Value.ToString().Length = 0 Then
                    Profit += Integer.Parse(DataGridView1.Rows(counter).Cells("Amount").Value.ToString())
                End If
            End If
        Next
        TextBox6.Text = Profit

this code working well if the datagridview is empty
but if i'm using this code with the exist info then an error occurred
"input string is not in a correct format"
any ideas??


Is This A Good Question/Topic? 0
  • +

Replies To: Question about sum a column in dataGrip view

#2 SeMiC  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-May 12

Re: Question about sum a column in dataGrip view

Posted 10 February 2013 - 05:43 AM

guys thank you
now it is working well
the profit has decimal numbers
so i have changed it to double and it is working well now
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1