Solved

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

Posted on 2007-11-17
7
303 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 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