Results 1 to 5 of 5

Thread: Add items in listview subitem?

  1. #1
    Fanatic Member
    Join Date
    May 09
    Posts
    868

    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
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,742

    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.

  3. #3
    Super Moderator Hack's Avatar
    Join Date
    Aug 01
    Location
    Searching for mendhak
    Posts
    58,283

    Re: Add items in listview subitem?

    Moved From The CodeBank (which is for sharing code rather than posting questions )
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 05
    Location
    Sydney, Australia
    Posts
    80,742

    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.

  5. #5
    Super Moderator Hack's Avatar
    Join Date
    Aug 01
    Location
    Searching for mendhak
    Posts
    58,283

    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
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •