I want to get the total sum of the amount column. How can I display the total sum to the textbox total? Any possible way to do it? Please help. Thanks!

Recommended Answers

All 7 Replies

is the datagrid bound or unbound?

Try :

        Dim temp As Long = 0
        For i = 0 To DataGridView1.Rows.Count - 1
            temp = temp + DataGridView1.Item(6, i).Value 'Column 6 is Amount
        Next
        Total.Text = temp

If the source for the DataGrid is a database you should be able to do it with a single query. If you provide more detail perhaps I can suggest something.

the datagrid is bound

the datagrid is bound

You can use SUM function to get total amount.
select sum(amount) as TotalAmount from TableName

    Label.Text = "Total Mount = " & ((From NetMount As DataGridViewRow In DataGridView1.Rows Where NetMoun.Cells(6).FormattedValue.ToString <> "" Select CInt(NetMoun.Cells(6).FormattedValue)).Sum)

Thanks for the help everyone.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.