Either idea -- preventing the user from unchecking the last checked item, or validating that at least one item is checked before proceeding -- is fairly straightforward to implement.
How to prevent the user from unchecking the last checked item
1. Make sure at least one item is checked to begin with (e.g., in your form's Load
event):
Private Sub frm_Load(ByVal sender As Object, ByVal e As EventArgs)
clb.SetItemChecked(0, True) ' whatever index you want as your default '
End Sub
2. Add some simple logic to your ItemCheck
event handler:
Private Sub clb_ItemCheck(ByVal sender As Object, ByVal e As ItemCheckEventArgs)
If clb.CheckedItems.Count = 1 Then ' only one item is still checked... '
If e.CurrentValue = CheckState.Checked Then ' ...and this is it... '
e.NewValue = CheckState.Checked ' ...so keep it checked '
End If
End If
End Sub
How to validate that at least one item is checked
Private Sub btn_Click(ByVal sender As Object, ByVal e As EventArgs)
' you could also put the below in its own method '
If clb.CheckedItems.Count < 1 Then
MsgBox("You must check at least one item.")
Return
End If
' do whatever you need to do '
End Sub