2012-07-16 25 views
0

如何檢查列表框是否被選中或不如何檢查列表框檢查或不

列表1

checkbox item 

checkbox Raja 
checkbox Raman 
checkbox Vijay 

從我要檢查whethere複選框被選中的列表1或不

如何寫在VB6代碼

需要VB6代碼幫助

回答

6

在這裏,我是代碼:

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 

編輯

如果你想找出選定的項目,你可以做這樣的:

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