List(Of String) Add and Remove Method : Visual Basic Programming
List(Of String) Add and Remove Method : Visual Basic Programming
List is a generic implementation of Array List. List can store only one type of objects, that type supplied as its generic parameter. List class is a collection and defined in the System.Collections.Generic namespace and it provides the methods and properties like other Collection classes such as add, insert, remove, search etc.
Public Class Form1
Dim Product_Names As New List(Of String)()
Private Sub AddProduct_Click(sender As Object, e As EventArgs) Handles AddProduct.Click
Product_Names.Add(TextBox1.Text)
ViewProduct()
TextBox1.Text = String.Empty
End Sub
Sub ViewProduct()
ListBox1.Items.Clear()
For Each Product As String In Product_Names
ListBox1.Items.Add(Product)
Next
NoOfProducts.Text = Product_Names.Count
End Sub
Private Sub RemoveProduct_Click(sender As Object, e As EventArgs) Handles RemoveProduct.Click
Product_Names.Remove(ListBox1.SelectedItem)
ViewProduct()
End Sub
Comments
Post a Comment