I am trying to save a list variable to My.Settings
, but I cannot find a type that works. I am using Visual Studio 2017. Here is how I built the list...
Dim Parameters As New List(Of String)
Parameters.Add("Item1")
Parameters.Add("Item2")
The error comes up when trying to load or save the setting.
Dim Times As New List(Of String)
Times = My.Settings.Times
or
My.Settings.Item("Times") = Times
though the latter doesn't show up as an error but it crashes the program.
I have tried setting the type of setting to String
, StringCollection
, ListDictionary
, etc. but to no avail.
A
System.Collections.Specialized.StringCollection
is the most common one used, although you cannot assign aList(Of String)
to it directly as they are different types.Instead you have to iterate your
List(Of String)
and add every item to theMy.Settings
list:Likewise, when reading it back into the
List(Of String)
: