如果在列表视图中选中某个项目,如何启用按钮?我试过这个并摆弄它但没有运气。有人可以帮忙吗?
Private Sub lvCustomers_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lvCustomers.SelectedIndexChanged
For Each x As ListViewItem In lvCustomers.Items
If x.Checked Then
btnConfirmOrder.Enabled = True
ElseIf x.Checked = False Then
btnConfirmOrder.Enabled = False
End If
Next
End Sub
答案 0 :(得分:0)
Private Sub lvCustomers_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lvCustomers.SelectedIndexChanged
btnConfirmOrder.Enabled = lvCustomers.Items.Any(Function(x) x.Checked)
End Sub
答案 1 :(得分:0)
以下是使用我在评论中描述的事件和集合的示例
Private Sub ListView1_ItemChecked(sender As Object, e As ItemCheckedEventArgs) Handles lvCustomers.ItemChecked
'checkeditems collection keeps track of only items that are checked
'if a single item is checked lvCustomer.CheckedItems.Count > 0
'becomes true and therefore the button is enabled. This event
'will respond with any check or uncheck of a checkbox in the LV
btnConfirmOrder.Enabled = lvCustomers.CheckedItems.Count > 0
End Sub