Add strings to a stringcollection or list
how can I add strings to a stringcollection in the settings, or add items to a list(Of String/Object) and how do you add it the items back in the stringcollection or (Of String/Object) to a Listbox.
Example:
Code:
StringCollection.Add(String)
I'm basically trying to store items into a listbox and I run a certain function, it will add the items to a Listbox.
Code:
StringCollection.AddRange(ListBox)
Re: Add strings to a stringcollection or list
When your form loads, get the items using:
Code:
Dim values = If(My.Settings.MySettingName?.Count > 0, My.Settings.MySettingName, New Specialized.StringCollection())
MyListBox.Items.AddRange(values.Cast(Of String).ToArray())
Then when you want to add a value to to the collection, use:
Code:
Dim value = InputBox("New Value: ")
If (My.Settings.MySettingName Is Nothing) Then
My.Settings.MySettingName = New Specialized.StringCollection() From { value }
Else
My.Settings.MySettingName.Add(value)
End If
My.Settings.Save()
MyListBox.Items.Add(value)