count limit in listbox

novice:)

Member
Joined
Apr 23, 2010
Messages
5
Programming Experience
Beginner
basic question which i cant figure out is i have a listbox and i total up all the values in it and send it to a text box.
but in the listbox i cant have more than 10 items in it i at the moment have a message box telling me how many items i have in the listbox which is simply
MsgBox(ListBox2.Items.Count())
when the 10th item is entered i need it to not allow me to enter anymore
so i know it needs to go 0-9 but not sure how to implement it.
 
A simple If statement checking to see how many items are in the ListBox before adding should suffice.

Not sure how you're adding items to the textbox so I just used a textbox and a button.

VB.NET:
    Private Sub uxAddToListBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uxAddToListBox.Click
        If Me.uxItemsList.Items.Count < 10 Then
            Me.uxItemsList.Items.Add(CInt(Me.uxEnteredValue.Text))
        Else
            MessageBox.Show("Maximum number of items already entered.")
        End If
    End Sub
 
Back
Top