1,105,340 Community Members

Calculate Total Of Column In Listview VB.NET

Member Avatar
TIP.Synergy
Junior Poster in Training
54 posts since Jan 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi to Everyone,

I want to get the total (column) amount using Listview w/o database VB.NET

Help me please...

Thanks..
_______________________________________________________________________________________________________

lstitems

Item Name | Unit Price | Quantity | Amount
------------------------------------------------------------
Sample1 | 100.00 | 1 | 100.00

Sample2 | 100.00 | 1 | 200.00

Sample3| 100.00 | 1 | 200.00
______________________________________

Label or Textbox ----> Total 500.00

Member Avatar
Teme64
Veteran Poster
1,039 posts since Aug 2008
Reputation Points: 189 [?]
Q&As Helped to Solve: 208 [?]
Skill Endorsements: 9 [?]
 
0
 

Here's the simplest way. This calculates the sum of the fourth column

Dim TotalSum As Double = 0
Dim TempNode As ListViewItem

For Each TempNode In ListView1.Items
  TotalSum += CDbl(TempNode.SubItems.Item(3).Text)
Next
MsgBox(TotalSum) ' Debug

and it assumes that each item is a valid number.

A bit safer solutions uses TryParse to check validity:

Dim TotalSum As Double = 0
Dim TempNode As ListViewItem
Dim TempDbl As Double

For Each TempNode In ListView1.Items
  If Double.TryParse(TempNode.SubItems.Item(3).Text, TempDbl) Then
    TotalSum += TempDbl
  End If
Next
MsgBox(TotalSum)

and again calculates the sum of the fourth column.

HTH

Member Avatar
TIP.Synergy
Junior Poster in Training
54 posts since Jan 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I'll try your code and i think it will work... Thanks to you Teme64 GodBless

Member Avatar
TIP.Synergy
Junior Poster in Training
54 posts since Jan 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I'll try your code and i think it will work... Thanks to you Teme64 GodBless

Member Avatar
TIP.Synergy
Junior Poster in Training
54 posts since Jan 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

THANK YOU... Teme64 IT WORKS... :) THUMBS UP!

Member Avatar
Teme64
Veteran Poster
1,039 posts since Aug 2008
Reputation Points: 189 [?]
Q&As Helped to Solve: 208 [?]
Skill Endorsements: 9 [?]
 
0
 

Hi! Nice to hear that you got answer to your problem. Could you please mark the thread as solved. Thank you!

Question Answered as of 3 Years Ago by Teme64
Member Avatar
TIP.Synergy
Junior Poster in Training
54 posts since Jan 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi sir, how about if going to display total quantity of items rowcount? On the top of screen there's 3 example should display Total Quantity = 3 Thx

Member Avatar
codeorder
Postaholic
2,027 posts since Aug 2010
Reputation Points: 197 [?]
Q&As Helped to Solve: 390 [?]
Skill Endorsements: 10 [?]
 
0
 

Have you tried ".SubItems.Item(2).Text"?

If Double.TryParse(TempNode.SubItems.Item(2).Text, TempDbl) Then

..Or maybe ".SubItems.Item(1).Text" to get the Unit Price Total of the "second" Column?

Member Avatar
TIP.Synergy
Junior Poster in Training
54 posts since Jan 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i mean total item in listview

Product Name
a
b
c
d

total item = 4

Member Avatar
codeorder
Postaholic
2,027 posts since Aug 2010
Reputation Points: 197 [?]
Q&As Helped to Solve: 390 [?]
Skill Endorsements: 10 [?]
 
0
 
MsgBox(ListView1.Items.Count)
Member Avatar
TIP.Synergy
Junior Poster in Training
54 posts since Jan 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

*_* AHAHA thx codeorder, It works :)

Member Avatar
TIP.Synergy
Junior Poster in Training
54 posts since Jan 2011
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thanks Sir codeorder, It works

Member Avatar
gd740
Newbie Poster
10 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hello, then how to achieve the option inserting the total of the sum into the mysql database?

Member Avatar
codeorder
Postaholic
2,027 posts since Aug 2010
Reputation Points: 197 [?]
Q&As Helped to Solve: 390 [?]
Skill Endorsements: 10 [?]
 
0
 

See if this thread.reply of mine helps. :)

Member Avatar
gd740
Newbie Poster
10 posts since Oct 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

can i add the sum total of the column in the footer of listview?

Member Avatar
codeorder
Postaholic
2,027 posts since Aug 2010
Reputation Points: 197 [?]
Q&As Helped to Solve: 390 [?]
Skill Endorsements: 10 [?]
 
0
 

>>can i add the sum total of the column in the footer of listview?
If "footer" is the "header" Or "ColumnHeader", then see if this helps.

With ListView1
            .Columns(0).Text = "ListView1" '// Column1
            .Columns(1).Text = ".Count" '// Column2
        End With
Member Avatar
Dili1234
Junior Poster
169 posts since Aug 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 3 [?]
 
0
 

thank you.......................

klooonhie
Newbie Poster
2 posts since Sep 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

what if i remove 1 item the total has not been change..?

is there any solution for that

N.E.Y.O-01
Newbie Poster
3 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

You guys here are so GENEROUSE.......... :)

N.E.Y.O-01
Newbie Poster
3 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
0
 

What if, "I would like to create a query statement that would give me the sum of the column(total_bill)?"
like this:

("Select SUM(total_bill)FROM tbl_estimates WHERE estimation_date = '"& Textbox1.Text & "'",2)

I would like to Displat it in my listview.

My, Query statement is absolutely right, but then there is still an error that doesnt have a suggestion.

Maybe you guys could help me..... :)

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: