Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListView groups with totals and subtotals

Status
Not open for further replies.

bestmakis

Technical User
Nov 12, 2014
22
GR
Hi.

I have a ListView with groups.
Groups have columns with prices.

How I can do subtotals and totals at the end of every column and any group?
Any example?


Thank you.
 

You can do this, but it will not be automatic. That is, you will have to calculate the subtotals and totals yourself and add them to the ListView.

For subtotals, you can either:
1) Enable footers for the groups and put the subtotals there. The drawback to this is that the columns won't align.
2) Add the subtotal to the group as the last item.

For the overall Total, you will need to add a group at the bottom of the ListView, name it Total and put the total there.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thank you.

I find the solution
' Add a group with totals
Dim TotalSum, TotalSum1 As Double
Dim TempDbl As Double
TotalSum = 0
TotalSum1 = 0
For Each strmyGroupname In ListView1.Items
If Double.TryParse(strmyGroupname.SubItems(7).Text, TempDbl) Then TotalSum += TempDbl
If Double.TryParse(strmyGroupname.SubItems(8).Text, TempDbl) Then TotalSum1 += TempDbl
Next
Dim gp As ListViewGroup
gp = New ListViewGroup("total", "total")
ListView1.Groups.Add(gp)
Dim Item1 As New ListViewItem
Item1 = ListView1.Items.Add("total:", 0)
Item1.SubItems.Add("")
Item1.SubItems.Add("")
Item1.SubItems.Add("")
Item1.SubItems.Add("")
Item1.SubItems.Add("")
Item1.SubItems.Add("")
Item1.SubItems.Add(TotalSum)
Item1.SubItems.Add(TotalSum1)
Item1.Group = gp
ListView1.Update()
ListView1.EndUpdate()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top