15,749,203 members
See more:
Hi all,

I just need a help regarding datagridview control in vb.net

I have datagridview in my form ..i had bind it and i want to perform sum operation of different cell..

for eg:-
i have a "AMOUNT" column in my datagrideview and i want to add those "AMOUNT" cell value.. and display it in a textbox..

my datagridview looks like below..
amount | rate | total
--------------------------
1
3
4
so if i want the sum of "AMOUNT" ie:- "8" in a textbox.. then wat code should i write.. can u pleas help me out any one..pls..
Posted
rajantandel 12-Apr-11 1:47am
thanks to all Specailly Andy_L_J.

Solution 6

If you need to display your sum of all rows from GridView then follow any of the solutions above.
And if you want to calculate the total using amount*rate, then add data-column to your data-source data-table as;
`dataTable.Columns.Add("total", typeof(System.Double), "amount*rate");`

or
`dataTable.Columns.Add("grand_total", typeof(System.Double), "sum(amount)");`

RaviRanjanKr 18-Nov-11 15:23pm
5+

Solution 2

This[^] could help.

Solution 3

And if the data is coming from a datatable you can use Compute[^] method

Solution 5

This will get you started...

```Dim tot As Double = 0
With dgv
For Each d As DataGridViewRow In dgv
tot += CDbl(d.Cells("Amount").Value)
Next
End With```

Solution 7

Dim totalsum As Integer
For i As Integer = 0 To dst.Tables(0).Rows.Count - 3
totalsum += dst.Tables(0).Rows(i).Item("Purches_Item")

Next
txtTotlePur.Text = totalsum.ToString()

Solution 9

Dear All

At row level one can use below codes for getting totals of colum using button click or
Private Sub Table1DataGridView_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Table1DataGridView.CellEndEdit
event to get total

Dim tot As Double = 0
With Table1DataGridView
For Each d As DataRowView In Table1BindingSource
tot += CDbl(d.Row("Amount"))
Next
End With
lblTotal.Text = tot.ToString

Sunil Bhagwat