我想将listview中的复选框选项限制为2 求助。
If lvbooklist.CheckedItems.Count >= 2 Then
e.NewValue = CheckState.Unchecked
MsgBox("Only 2 Book can be borrow per day")
Else
End If
答案 0 :(得分:1)
您的代码应该在ItemCheck
事件中,并且您应该只是阻止CheckBox从Unchecked状态进入Checked状态(否则当您取消选中某个项目时它们也会收到一条消息你已经选择了两个):
Private Sub lvbooklist_ItemCheck(sender As Object, e As ItemCheckEventArgs) Handles lvbooklist.ItemCheck
If lvbooklist.CheckedItems.Count = 2 AndAlso e.CurrentValue = CheckState.Unchecked Then
e.NewValue = CheckState.Unchecked
MessageBox.Show("Only 2 Books can be borrowed per day.")
End If
End Sub