Results 1 to 9 of 9

Thread: [RESOLVED] please help; how to sum duplicate listview sub item

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    18

    Resolved [RESOLVED] please help; how to sum duplicate listview sub item

    i have listview with data like this,

    Name Total
    Jon 10
    Joe 15
    Trump 5
    Sarah 7
    Gina 16
    Jon 5
    Joe 5
    Sarah 10
    Biden 9


    i want sum duplicate total like this to my form preview,

    Name Total
    Jon 15
    Joe 20
    Trump 5
    Sarah 17
    Gina 16
    Sarah 10
    Biden 9

    Code:
    frmPreview.Print Tab(3); "Name";
    frmPreview.Print Tab(15); "Total";
    please help me thanks

  2. #2
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,391

    Re: please help; how to sum duplicate listview sub item

    Homework?
    Sam I am (as well as Confused at times).

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    18

    Re: please help; how to sum duplicate listview sub item

    @SamOscarBrown yes still need to learn a lot from the masters

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    8,391

    Re: please help; how to sum duplicate listview sub item

    Thought so....but, tell ya what...post what YOU have tried first. Just think of it in terms of iterating through the first column, and find duplicates. When you find them, you should be able to 'see' the value in the second column and save it to a variable (an array might be of benefit, but probably you're not into arrays yet.
    Sam I am (as well as Confused at times).

  5. #5
    Addicted Member
    Join Date
    Jan 2018
    Posts
    216

    Re: please help; how to sum duplicate listview sub item

    What data structures are you currently studying? Arrays, database tables, collection, dictionary? There's an answer for each type. If your data structure is a table, then I would start with learning how to do a SUM group by query.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    18

    Re: please help; how to sum duplicate listview sub item

    @ahenry @SamOscarBrown ok i am using access database and using command button to search my data from db to showing in my listvie and then my form1 have rightclick menu to view data as report

    Code:
    Private Sub cmdSearch_Click()
    
    Dim k As ListItem
    Form1.lvMain.ListItems.Clear
    myRecordset "Select * FROM QMain WHERE cdate(Format$(Tanggal, ""dd/mm/yyyy"")) BETWEEN #" & Format(DTPicker1.Value, "mm/dd/yyyy") & "# AND #" & Format(DTPicker2.Value, "mm/dd/yyyy") & "# ORDER BY ID;"
    While Not myrs.EOF = True
    Set k = Form1.lvMain.ListItems.Add(, , Format(myrs.Fields("Tanggal"), "DD/MM/YYYY"))
    k.SubItems(1) = myrs.Fields("NoPlat")
    k.SubItems(2) = myrs.Fields("Supir")
    k.SubItems(3) = myrs.Fields("Kenek")
    k.SubItems(4) = myrs.Fields("ritSupir")
    k.SubItems(5) = myrs.Fields("ritKenek")
    myrs.MoveNext
    Wend
    
    End Sub
    i want to showing report from my listview data after searching my db using rightclickmenu

    Code:
    Private Sub mnuDailyPreview_Click()
        frmPreview.Show
        CdailyView
    End Sub



    Code:
    Private Sub CdailyView()
    
            frmPreview.Move 3800, 2000
            frmPreview.Width = 14800
            frmPreview.Height = 10000
      
            frmPreview.Print
            frmPreview.FontBold = True
            frmPreview.FontSize = 10
            frmPreview.FontName = "Courier New"
            frmPreview.Print Tab(3); "Daily report"
            grs = String$(100, "-")
            frmPreview.FontBold = False
            frmPreview.FontSize = 9
            
            frmPreview.Print Tab(3); grs;
            frmPreview.Print Tab(3); "Tanggal";
            frmPreview.Print Tab(15); "No Pelat";
            frmPreview.Print Tab(27); "Supir";
            frmPreview.Print Tab(37); "Kenek";
            frmPreview.Print Tab(57); "ritSup";
            frmPreview.Print Tab(77); "ritKnk";
            frmPreview.Print Tab(3); grs;
            End If
    
            Dim i As Long
            With frmMain.lvMain
            For i = 1 To frmMain.lvMain.ListItems.Count
                         
                         frmPreview.Print Tab(3); frmMain.lvMain.ListItems(i);
                         frmPreview.Print Tab(15); frmMain.lvMain.ListItems(i).ListSubItems(1);
                         frmPreview.Print Tab(27); frmMain.lvMain.ListItems(i).ListSubItems(2);
                         frmPreview.Print Tab(37); frmMain.lvMain.ListItems(i).ListSubItems(3);
                         frmPreview.Print Tab(57); frmMain.lvMain.ListItems(i).ListSubItems(4);
                         frmPreview.Print Tab(77); frmMain.lvMain.ListItems(i).ListSubItems(5);
                         
            Next i
            End With
    
            grsT = String$(100, "=")
            frmPreview.Print Tab(3); grsT;
            frmPreview.Print Tab(3); ' i want show Sum duplicate item from my listview  like this
    
                                              Supir    Total                  Kenek         Total
         
                              =================================
                                                Jon        15                   Robert         50
                                                Joe        20                   Jose            25     
                                                Trump      5                   Tina            15
                                                Sarah     17
                                               Gina        16
                                               Sarah      10
                                               Biden        9
                               ------------------------------------------------------------------
                              Grant Total                92                                     90
    End Sub

    like that i want to do ....

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,335

    Re: please help; how to sum duplicate listview sub item

    Quote Originally Posted by joelin View Post
    @SamOscarBrown yes still need to learn a lot from the masters
    Yeah, right......
    Homework.....
    Joined in 2009 (13 years ago), at age what? 4 years old?
    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    18

    Re: please help; how to sum duplicate listview sub item

    Quote Originally Posted by Zvoni View Post
    Yeah, right......
    Homework.....
    Joined in 2009 (13 years ago), at age what? 4 years old?
    joining date is not guaranteed lol sometimes forget because i haven't used it for a long time

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Posts
    18

    Re: please help; how to sum duplicate listview sub item

    ok i have found the answer

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