Results 1 to 5 of 5

Thread: ListView groups with totals and subtotals

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2005
    Location
    Greece
    Posts
    61

    ListView groups with totals and subtotals

    Hi.

    I have a ListView with groups.
    Some 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.
    Last edited by makisbest; Mar 9th, 2015 at 01:24 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: ListView groups with totals and subtotals

    You appear to think that there's some magic to it. There isn't. You do the arithmetic and then add another item to the group.

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2005
    Location
    Greece
    Posts
    61

    Re: ListView groups with totals and subtotals

    OK, I agree... but how?? I am new to all this stuff.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: ListView groups with totals and subtotals

    Quote Originally Posted by makisbest View Post
    OK, I agree... but how?? I am new to all this stuff.
    I'm going to give you the benefit of the doubt and assume that you know how to do the arithmetic. As for adding the item, I would expect that you would already know how to do that because you must already have items in there if you have something to total. I'm confused as to where the actual issue is. If you're just waiting for someone to write the code for you then I'm not your man. If you have thought through what you need to do and, even better, had a go at doing it, then I'm more than happy to address a specific issue.

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2005
    Location
    Greece
    Posts
    61

    Re: ListView groups with totals and subtotals

    I make it work.... Thank you for the help.

    Code:
    ' 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()

Tags for this Thread

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