Results 1 to 5 of 5

Thread: Add items in listview subitem?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Add items in listview subitem?

    Hi, Is it possible to add up all the numbers in a listview sub item? For example column 3 has

    1
    2
    3
    8


    is it possible to make a label display the total by adding the numbers up?


    Regards
    Jamie

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

    Re: Add items in listview subitem?

    Loop through the items and, on each iteration, get the Text of the appropriate subitem and convert it to a number, then add that number to a running total. That running total would obviously be initialised to zero and, at the end of the loop, it contains the total for the column.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Add items in listview subitem?

    Moved From The CodeBank (which is for sharing code rather than posting questions )

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

    Re: Add items in listview subitem?

    Hmmm... I found this thread in the New Posts section and thought it was in the VB.NET forum. Apparently I can't see straight. If it's a VB6 ListView then the details may be a bit different to what I suggested but the principle will be the same.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Add items in listview subitem?

    Quote Originally Posted by jmcilhinney View Post
    Hmmm... I found this thread in the New Posts section and thought it was in the VB.NET forum.
    I had a feeling that is what you might have been thinking.

    Jamie: Try something like
    Code:
    Dim i As Long
    Dim lngTotal As Long
    
    For i = 1 To Listview1.ListItems.Count    
        lngTotal = lngTotal + Val(Listview1.ListItems(i).SubItems(3))    
    Next
    'do something with lngTotal

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