CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2013
    Posts
    27

    ListView groups with totals and subtotals

    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.

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: ListView groups with totals and subtotals

    1) you'll need to make the subtotals yourself. this isn't goign to go "automatically"
    If this needs to be at the bottom, then either:
    - enable the group footer and put the subtotal in there.
    THis may not be visually entirely what you want since it won't be aligned with the columns.
    - or add a subtotal item to the group

    2) there's no provision in listcontrol for a grand total
    you can add an extra "total" group and add a total item
    or
    have the total displayed outside of the listcontrol.

  3. #3
    Join Date
    Mar 2013
    Posts
    27

    Re: ListView groups with totals and subtotals

    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()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured