How can summarize item in a listview

Posted on 2004-10-28
Last Modified: 2013-12-26
I have the following 2 field in a grid
GroupField   TotalField
AAA            1
BBB            1
CCC            1
AAA            1
BBB            2
CCC            1
AAA            1
BBB            1
Now i need to provide a summary in a listview as follows

GroupField   TotalField
AAA             3
BBB            4
CCC            2

I have done the following

Private sub SetupListview

      with lvw.ColumnHeaders
          .Add, "Grp","Group,2000
            .Add, "Ttl","Total,2000
      end with
end sub

Private sub PopulateListView(Byval strGroup as string,intValue as integer)
      dim li as listItem
        dim liKey as string

liKey="k" & StrGroup
      if lvw.listitems.count > 0 Then

            for each li in lvw.listitems
                  if li.text=strGroup then
                        li.subItems(1)=IntValue + 1
                        SET LI=LVW.ListItems.Add(,likey,strGroup)
                  end if
            SET LI=LVW.ListItems.Add(,likey,strGroup)
      end if

end sub
Question by:Gabriel_Brienza
    LVL 14

    Accepted Solution

    try this

    Private Sub PopulateListView(ByVal strGroup As String, intValue As Integer)
    Dim lst As ListItem
         Set lst = lvw.FindItem(strGroup, lvwText, , lvwWhole)
         If lst Is Nothing Then
             Set lst = lvw.ListItems.Add(, , strGroup)
                lst.SubItems(1) = intValue
            lst.SubItems(1) = CInt(lst.SubItems(1)) + intValue
         End If
         Set lst = Nothing
    End Sub

    Author Comment

    fantastic .it worked very well

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Shellfire Box VPN + Lifetime Subscription

    The Shellfire Box easily connects all of your devices, even those that don't offer the possibility to establish a safe vpn connection. Access blocked content and surf safely, no matter where in the world you are located.

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    934 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now