Solved

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

Posted on 2007-11-17
7
299 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
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.

758 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

21 Experts available now in Live!

Get 1:1 Help Now