Results 1 to 3 of 3

Thread: Sum Values Of 1 Column in a Datagrid??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2003
    Posts
    154

    Sum Values Of 1 Column in a Datagrid??

    Is there a way...I can sum all the values of one column of a datagrid and display the total in a label??

    So...I have a column in my datagrid called "PAR_AMOUNT"....so for every item in the datagrid...I want to sum the values of the column "PAR_AMOUNT" and place the total in a label??

    Ex.

    Datagrid...
    Item 1 "567"
    item 2 "200"
    item 3 "300"


    Label.text = "1067"

    Thanks in advance!!

  2. #2
    Lively Member
    Join Date
    Nov 2002
    Location
    Malaysia
    Posts
    124
    yeah i need to know this solution too, can anyone help?

  3. #3
    Lively Member
    Join Date
    Nov 2002
    Location
    Malaysia
    Posts
    124

    Re: Sum Values Of 1 Column in a Datagrid??

    Originally posted by Neumee
    Is there a way...I can sum all the values of one column of a datagrid and display the total in a label??

    So...I have a column in my datagrid called "PAR_AMOUNT"....so for every item in the datagrid...I want to sum the values of the column "PAR_AMOUNT" and place the total in a label??

    Ex.

    Datagrid...
    Item 1 "567"
    item 2 "200"
    item 3 "300"


    Label.text = "1067"

    Thanks in advance!!


    Code:
        Private Sub cmdShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShow.Click
            ShowBalance(DataSet11)
        End Sub
    
        Private Sub ShowBalance(ByVal dataset As DataSet)
            Try
                Dim dataTable As DataTable = dataset.Tables(0)
                Dim Rows As Integer = dataTable.Rows.Count
                Dim Row As Integer = 0
                Dim number As Integer = 0
                While Row < Rows
                    number = Convert.ToInt32(dataTable.Rows(Row)(1))
                    txtTotalBalance.Text = number + Convert.ToInt32(txtTotalBalance.Text)
                    Row += 1
                End While
            Catch ShowBalanceException As System.Data.OleDb.OleDbException
                MessageBox.Show(ShowBalanceException.Message)
            End Try
        End Sub

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