Results 1 to 3 of 3

Thread: [2008] How to Sum up a specific Column

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2008
    Location
    Philippines
    Posts
    70

    [2008] How to Sum up a specific Column

    Can someone help me on how to sum up all the values in specific column in a DataGridView.

    Name No. of Apples
    Jayson 10
    Troe 10
    Edna 10

    imagine this is the sample data in the Datagridview. how can i add all the Number of apples??? THANKS

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] How to Sum up a specific Column

    Is this grid bound to a DataTable? If so then you'd call the table's Compute method, e.g.
    vb.net Code:
    1. Dim sum As Integer = CInt(myDataTable.Compute("SUM(SomeColumn)", Nothing))
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] How to Sum up a specific Column

    And if the datagridview is not bound, you'll have to manually loop through all its rows and add the values yourself.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width