Find Total amount of one column in Datagrid and put it in textbox

I have a datagrid(DataGridView1) that have some columns from dataset,
the last column is(price). I want to find the total amount of this column(price) and put it in the textbox.
how can I fix that
Who is Participating?
JunnickYsoConnect With a Mentor Commented:
You can do loops like this::

Dim intRowCount as Integer
Dim decPrice as Decimal = 0

'dtTable is a DataTable in your dataset that is binded in your datagridview

Do until intRowCount = dtTable.Rows.Count
            decPrice = decPrice + CDec(dtTable.Rows(intRowCount).Item(4))
            'Were Item(4) is your column named  PRICE

            If intRowCount <> dtTable.Rows.Count - 1 Then
                       intRowCount = intRowCount + 1
                       Exit Do
            End If

TextBox1.Text = format(decPrice, "#,##0.#0")

thats all....... hope this could help
JassimiAuthor Commented:
where should I write this code?
is it in same textbox?
JassimiAuthor Commented:
not this what I want
I want to calculate the total amount of the price column which is in datagrid in textbox
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.


where should I write this code?
is it in same textbox?

-where should I write this code?
I assume you a have a button that would trigger the calculation event. And the code provided you should be in that code block.

-is it in same textbox?
Probably yes? That was just an example if your using other TextBox name then set to the respective textbox!

maybe you can submit you partial code and feed me more of what your trying to do: :-)

JassimiAuthor Commented:
sorry for late,
I don't have a button to calculate the event,
I put a textbox under the datagridview to calculate the total amount of the price column,

when I tried your code, it doesn't do that, it just calculate the rows of the datagrid
JassimiAuthor Commented:
its working now but by temptable
not by original database source

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.