checkedlistbox vb.net事件检查是否已选中

时间:2016-10-01 18:32:43

标签: vb.net events checkedlistbox handles

如果我有一个带有项目(苹果,胡萝卜,青蛙)的checkedlistbox以及只有在checkedlistbox中选择了至少一个项目时才启用的按钮,我会使用哪个事件?

其中' ListofURLFromDB_Listbox'是checkedlistbox和' Process_FromList_URLs_btn'是按钮

我试过.ItemCheck,.SelectedIndexChanged和.SelectedValueChanged

    If (ListofURLFromDB_Listbox.SelectedIndex = -1) Then
        Process_FromList_URLs_btn.Enabled = False
    ElseIf (ListofURLFromDB_Listbox.SelectedIndex > -1) Then
        Process_FromList_URLs_btn.Enabled = True
    End If

非常感谢

1 个答案:

答案 0 :(得分:0)

您可以使用SelectedIndexChanged事件并计算已检查项目的数量:

 Private Sub ListofURLFromDB_Listbox_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListofURLFromDB_Listbox.SelectedIndexChanged
     If ListofURLFromDB_Listbox.CheckedItems.Count > 0 Then
            Process_FromList_URLs_btn.Enabled = True ' If checked items count is > 0
     Else
            Process_FromList_URLs_btn.Enabled = False
     End If
 End Sub