Total Pageviews

Thursday, November 10, 2016

Limit the number of items to add in a ListBox in Visual Basic 2015

In this blog post you will learn how to limit the number of items someone can insert in a ListBox. 
Let say you have a task to limit the entrance of items to be 5. Here is the source code:

        Dim item As Integer
        item  = TextBox1.Text
        If Not ListBox1.Items.Count = 5 Then
            ListBox1.Items.Add(item)
        Else
            MsgBox("You already entered 5 grades")
        End If

Very simple and clean code.

No comments:

Post a Comment