Results 1 to 7 of 7

Thread: [RESOLVED] Adding Up Numbers In ListView Column

Threaded View

  1. #4
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: Adding Up Numbers In ListView Column

    The Listview in .NET is 0-based (VB6 is 1-based), so if you have 53 items, then loop from 0 to 52. ListView1.Items.Count will return 53, which means you're looping from 0 to 53 and index 53 doesn't exist.

    You don't have to do "intRptTotal = intRptTotal + ....", but you can do "intRptTotal += ..." instead.

    vb.net Code:
    1. Dim intRptTotal As Integer = 0
    2. For i As Integer = 0 To lvwReportCount.Items.Count - 1
    3.       intRptTotal += CInt(lvwReportCount.Items(i).SubItems(1).Text)
    4. Next

    Alternatively, you can also do a for each loop.

    vb.net Code:
    1. For Each lvw As ListViewItem In lvwReportCount.Items
    2.     intRptTotal += CInt(lvw.SubItems(1).Text)
    3. Next
    Last edited by Chris001; Dec 29th, 2010 at 10:13 AM.

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