Results 1 to 7 of 7

Thread: [RESOLVED] Sum of checked list item!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Resolved [RESOLVED] Sum of checked list item!

    Hi Dears

    I need your help
    I want to collect (Sum) the amount of selected items from the list view to TextBox (or label). my code does not work.
    This is my code:
    **********************
    Dim i, A
    A = 0
    For i = 1 To ListView1.SelectedItem.Checked = True
    A = A + ListView1.ListItems(i).SubItems(2)
    Next
    Text5.Text = A
    ***********************
    Please Help!
    Name:  Test123e.jpg
Views: 481
Size:  44.9 KB

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

    Re: Sum of checked list item!

    loop through the entire listview, and IF an item is checked, then do your summation.

  3. #3
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: Sum of checked list item!

    Maybe something like this:

    Code:
    Dim I as Integer, A as Integer
     A = 0
     For i = 1 To ListView1.listitems.count
         if listview1.SelectedItem.Checked = True then                         
               A = A + ListView1.ListItems(i).SubItems(2)
         end if
     Next
     Text5.Text = A

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

    Re: Sum of checked list item!

    oops

    do this:

    Code:
       Dim lvwItem As ListItem, A As Integer
       For Each lvwItem In ListView1.ListItems
            If lvwItem.Checked = True Then
                A = A + ListView1.ListItems(1).SubItems(2)
            End If
       Next lvwItem
    Text5.Text = A

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Re: Sum of checked list item!

    Dear SamOscarBrown Thank you for this code but it does not work. when i check any item, only the first item will show in text5

    Name:  trv.GIF
Views: 458
Size:  3.6 KB


    I changed the code to

    Dim lvwItem As ListItem, A As Integer
    For Each lvwItem In ListView1.ListItems()
    If lvwItem.Checked = True Then
    A = A + ListView1.ListItems(lvwItem).SubItems(2)
    End If
    Next lvwItem
    Text5.Text = A

    <<< But still this not work. >>>>

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,622

    Re: Sum of checked list item!

    Mea Culpa---

    here:

    Code:
       Dim i As Integer, A As Integer
            
                For i = 1 To ListView1.ListItems.Count
                     If ListView1.ListItems(i).Checked = True Then
                          A = A + ListView1.ListItems(i).SubItems(2)
                     End If
                Next I
    Text5.text = A

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2016
    Posts
    104

    Re: Sum of checked list item!

    Thank you Dear SamOscarBrown it work perfectly

Tags for this Thread

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