Results 1 to 5 of 5
  1. #1
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Count of selected Items in Listbox (VB6)

    Is there a direct Property to get to the count of selected items in a MultiSelect ListBox, or do I have to loop through their selected status like this (air code):

    Private Sub lstMyList_Click()
    Dim intC As Integer, intSel As Integer
    With lstMyList
    For intC = 1 To .ListCount
    If .Selected(intC) Then intSel = intSel + 1
    Next intC
    If .ListCount = intSel Then
    chkSelectAll = True
    Else
    chkSelectAll = False
    End If
    End With
    End Sub
    -John ... I float in liquid gardens
    UTC -7ąDS

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Count of selected Items in Listbox (VB6)

    According to the MSDN documentation, the SelCount property returns the number of selected items in a ListBox control.

  3. #3
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Re: Count of selected Items in Listbox (VBA)

    Sorry, but I mistitled the "Version" section of my post, this is for VBA, not VB6, and .SelCount doesn't appear to be a Property in the VBA Forms 2 Library. And my stupid loop code isn't working either. (BTW, it's for <!post=this,443421>this<!/post> albatross around my neck, still working on UI cosmetics and bugs.)
    -John ... I float in liquid gardens
    UTC -7ąDS

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: Count of selected Items in Listbox (VBA)

    You're out of luck then - SelCount is a property of the VB6 list box, not of the MSForms list box. Looping through the list items and checking their Selected property is the only way for those...

    Apart from that:
    - Use the lstMyList_Change event instead of the lstMyList_Click event.
    - The item index is zero-based, so the loop should go For intC = 0 To .ListCount - 1

  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 5 Times in 5 Posts

    Re: Count of selected Items in Listbox (VBA)

    Thank you Hans, that fixed everything in one shot. I then found that the corrected code overrode the "Select all items" checkbox, but I used the technique you described <!post=here,467255>here<!/post> to manage the problem. You are like the valiant tailor in the Grimm Brothers fairy story "seven at one stroke". <img src=/S/bow.gif border=0 alt=bow width=15 height=15>
    -John ... I float in liquid gardens
    UTC -7ąDS

Posting Permissions

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