Results 1 to 10 of 10

Thread: Listbox help - Count selected items

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    137

    Listbox help - Count selected items

    Hi, I assume this have been asked and answered before, but can't seem to find any info on this.. How do you get the number of selected items in a listview without having to loop through all the records?
    Thanks
    John

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I think they only way you can do it is to loop there the items in the listview and check their selected prop.

  3. #3
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    If you have to loop through them to check their property, the what is the SelCount property for?
    <removed by admin>

  4. #4
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    But if you really wanted to do it with a loop...

    Dim num As Integer
    num = 0
    For x = 0 To List1.ListCount - 1
    If List1.Selected(x) = True Then
    num = num + 1
    End If
    Next
    MsgBox num
    <removed by admin>

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    137
    Hi, I actually found this thread that have a solution.. Seemed to work..

    http://forums.vb-world.net/showthrea...threadid=13921

    Second last reply..

    John

  6. #6
    New Member
    Join Date
    Jan 2011
    Posts
    1

    Re: Listbox help - Count selected items

    use this.
    ListBox.ItemsSelected.Count

  7. #7

  8. #8
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Listbox help - Count selected items

    And furthermore, this thread is almost 10 years old! There is no need to post replies to old/dead threads.

  9. #9

  10. #10
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Listbox help - Count selected items

    Kind of fun to respond to it anyway. I needed a refresher course. Build a form with a label and a list box. Then apply this code:
    Code:
    Private Sub Form_Load()
    ' Sample Data
    For I = 1 To 100
        List1.AddItem I
    Next
    End Sub
    
    Private Sub List1_Click()
    Dim SlCount As Integer
    For I = 0 To List1.ListCount - 1
        If List1.Selected(I) = True Then SlCount = SlCount + 1
    Next
    Label1.Caption = SlCount & " Item(s) Selected"
    End Sub
    Doctor Ed

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