|
-
Mar 10th, 2003, 01:24 PM
#1
Thread Starter
Addicted Member
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!!
-
Mar 12th, 2003, 08:11 PM
#2
Lively Member
yeah i need to know this solution too, can anyone help?
-
Mar 14th, 2003, 02:13 AM
#3
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|