Combo box control help

beepstreet

Member
Joined
Oct 22, 2007
Messages
7
Programming Experience
Beginner
Say i had 5 items (cd 1, cd 2 , cd 3 , cd 4, cd 5) in a combo box and i want to make sure that only 3 items can be selected so an error message if 3 or more are selected.
How would you put a restriction so it will only allow 3 choices and the error message?

Also could this be done with a checked list box?
 
It can't be done with a ComboBox because it only supports one selection. You'd have to use a ListBox or a CheckedListBox. With a CheckedListBox you could do it like this:
VB.NET:
Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, _
                                      ByVal e As ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
    If e.CurrentValue = CheckState.Unchecked AndAlso Me.CheckedListBox1.CheckedItems.Count = 3 Then
        MessageBox.Show("The maximum number of selections have already been made.", _
                        "Invalid Selection", _
                        MessageBoxButtons.OK, _
                        MessageBoxIcon.Warning)
        e.NewValue = CheckState.Unchecked
    End If
End Sub
 
Thanks!
Before i would use an inputbox so when i clicked the button another form would appear to add text. How would i make it so it opens up this combo box instead of the textbox?
 
Back
Top