Reputation: 119
I have been looking for the specified code all day long, browsing through the MSDN libraries from microsoft, but I wasn't able to find or come up with a solution:
Question: How can I add a string to an existing array?
I have been trying this
Dim Items() As String
Items = ListBox1.Items.Cast(Of String).ToArray
Array.Reverse(Items)
Me.ListBox1.Items.Clear()
Me.ListBox1.DataSource = Items
**Items.add("Add This to my array")**
But this doesn't work unfortunately.
My code is loading a populated listbox into an array (reverses the entries, and then cleans the listbox before populating it with the array).
How can I add to this array now?
Upvotes: 0
Views: 3216
Reputation: 1556
Try this.....
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim Items As List(Of String)
Items = ListBox1.Items.Cast(Of String).ToList
Items.Reverse()
Items.Add("Add This to my array")
Me.ListBox1.Items.Clear()
Me.ListBox1.DataSource = Items
End Sub
End Class
almost identical code (slightly rearranged), using a List instead of an array
Upvotes: 1