How to add arraylist value to listbox in vb.net

How to add arraylist value to listbox in vb.net

This function clears out the ListBox, displays the array in the ListBox,

and then displays the count (the total number of items in the ArrayList) in

the title bar of the form
-------------------------------------------------------------------------------------------------

Dim MyArray As New ArrayList
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

MyArray.Add("key")
MyArray.Add("Name")
MyArray.Add("Address")
add_to_listbox() 'function call for add listbox

End Sub


Public Sub add_to_listbox() 'function for adding arraylist value to listbox
ListBox1.Items.Clear()
ListBox1.Items.AddRange(MyArray.ToArray)
Me.Text = MyArray.Count.ToString
End Sub
-----------------------------------------------------------------------------------------

No comments: