Solved

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

Posted on 2007-11-17
7
300 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now