Search code examples
vb6

How to check the listbox is checked or not


How to check whether the listbox is checked or not

list1

checkbox item

checkbox   Raja
checkbox   Raman
checkbox   Vijay

From the list1 i want to check whethere checkbox is checked or not

How to write a code in vb6

Need Vb6 code Help


Solution

  • Here is the code:

    Private Sub Command1_Click()
        If List1.SelCount > 0 Then
            MsgBox "Some items are selected"
        Else
            MsgBox "Sorry,no items are selected !"
        End If
    End Sub
    

    EDIT

    If you want to find out the selected items, you could do it like this:

    Private Sub Command2_Click()
        Dim i As Long
    
        For i = 0 To List1.ListCount - 1    'loop through the items in the ListBox
            If List1.Selected(i) = True Then    ' if the item is selected(checked)
                MsgBox List1.List(i)        ' display the item
            End If
        Next
    End Sub