?
Solved

How can summarize item in a listview

Posted on 2004-10-28
2
Medium Priority
?
228 Views
Last Modified: 2013-12-26
I have the following 2 field in a grid
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
          .Clear
          .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
                  else
                        SET LI=LVW.ListItems.Add(,likey,strGroup)
                        li.subItems(1)=IntValue
                  end if
            next
      else
            
            SET LI=LVW.ListItems.Add(,likey,strGroup)
            li.subItems(1)=IntValue
      end if

end sub
0
Comment
Question by:Gabriel_Brienza
2 Comments
 
LVL 14

Accepted Solution

by:
Shiju Sasidharan earned 120 total points
ID: 12436130
Hi
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
     Else
        lst.SubItems(1) = CInt(lst.SubItems(1)) + intValue
     End If
     Set lst = Nothing
End Sub
'-------------------------------------
;-)
Shiju
0
 

Author Comment

by:Gabriel_Brienza
ID: 12442251
fantastic .it worked very well
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

588 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