Solved

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

Posted on 2007-11-17
7
304 Views
Last Modified: 2010-04-14
hi..
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
Thanks
0
Comment
Question by:Jassimi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 4

Accepted Solution

by:
JunnickYso earned 50 total points
ID: 20303712
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
            Else
                       Exit Do
            End If
Loop

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


thats all....... hope this could help
0
 
LVL 2

Author Comment

by:Jassimi
ID: 20303795
where should I write this code?
is it in same textbox?
0
 
LVL 2

Author Comment

by:Jassimi
ID: 20304418
not this what I want
I want to calculate the total amount of the price column which is in datagrid in textbox
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Expert Comment

by:JunnickYso
ID: 20310715
Jassimi:

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: :-)

0
 
LVL 2

Author Comment

by:Jassimi
ID: 20322890
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
0
 
LVL 2

Author Comment

by:Jassimi
ID: 20497872
ok..
its working now but by temptable
not by original database source

thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question