Question: 13. In this exercise, you learn how to use the Items collections Insert, Remove, RemoveAt, and Clear methods. You also learn how to use the

13. In this exercise, you learn how to use the Items collection’s Insert, Remove, RemoveAt, and Clear methods. You also learn how to use the Items collection’s Count property.

Open the VB2015\Chap06\Items Solution\Items Solution (Items Solution.sln) file.

a. The Items collection’s Insert method allows you to add an item at a desired position in a list box during run time. The Insert method’s syntax is object.Items.Insert(position, item), where position is the index of the item.

Code the btnInsert_Click procedure so it adds your name as the fourth item in the list box.

b. The Items collection’s Remove method allows you to remove an item from a list box during run time. The Remove method’s syntax is object.Items.Remove(item), where item is the item’s value. Code the btnRemove_Click procedure so it removes your name from the list box.

c. Like the Remove method, the Items collection’s RemoveAt method also allows you to remove an item from a list box while an application is running. However, in the RemoveAt method, you specify the item’s index rather than its value. The RemoveAt method’s syntax is object.Items.RemoveAt(index), where index is the item’s index. Code the btnRemoveAt_Click procedure so it removes the second name from the list box.

d. You can use the Items collection’s Clear method to remove all items from a list box during run time. As you learned in this lesson, the method’s syntax is object.Items.Clear(). Code the btnClear_Click procedure so it clears the items from the list box.

e. The Items collection’s Count property stores the number of items contained in a list box. Code the btnCount_Click procedure so it displays (in a message box) the number of items listed in the lstNames control.

f. Save the solution, and then start and test the application.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock