12,509,269 members (61,871 online)
Rate this:
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 8-Apr-11 19:03pm
rajantandel 12-Apr-11 1:47am

thanks to all Specailly Andy_L_J.

Rate this:

Rate this:

Rate this:

## 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+
Rate this:

## Solution 2

This[^] could help.
Rate this:

## Solution 3

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

## 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
```
Rate this:

## 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()
Rate this:

## 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

Top Experts
Last 24hrsThis month
 OriginalGriff 331 Maciej Los 205 Suvendu Shekhar Giri 170 CPallini 140 Richard Deeming 125
 OriginalGriff 7,907 ppolymorphe 4,062 Maciej Los 3,981 David_Wimbley 3,306 Karthik Bangalore 3,151