Results 1 to 3 of 3

Thread: Using Selected property in a ListBox with Style = CheckBox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458
    Hi,
    Can anyone provide an example how to use .Selected property on a listbox to check which itmes are currently checked? As I mentioned in the subject, it's a listbox with Style set to 1-checkbox.
    Thanks
    Thanks

    Tomexx.

  2. #2
    Hyperactive Member vbzero's Avatar
    Join Date
    Aug 2000
    Location
    Vienna
    Posts
    347

    Arrow

    Code:
    'Add 2 items to a listbox:
    
    List1.AddItem "String1", 0
    List1.AddItem "String2", 1
    
    'Remove the 1 item:
    
    List1.RemoveItem 0
    
    'Verify which items is checked:
    
    If List1.Selected(0) = True Then
        MsgBox "String2 is selected"
    End If
    
    'Note: If you remove 1 item, the index numbers
    'of all other items will change!
    
    'e.g. If you remove item(0) just like in this
    'example, the item which was named "String2"
    'gets the index 0.
    
    'Thats why I typed "String2" in the messagebox statement.

  3. #3
    Guest
    Add to a Form with a ListBox and CommandButton
    Code:
    Private Sub Command1_Click()
        'Loop through and check if they are selected
        For I = 0 To List1.ListCount - 1
            If List1.Selected(I) = True Then MsgBox (List1.List(I) & " is selected")
        Next I
    End Sub
    
    Private Sub Form_Load()
        'Add items to ListBox
        For I = 0 To 10
            List1.AddItem "Number" & I
        Next I
    End Sub

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