The only type of collection that allows you to use the settings constructor is System.Collections.ArrayList. If you use an ArrayList, all of its element types must be serializable (have the [Serializable] attribute or implement System.Runtime.Serialization.ISerializable.)
Here is some code to get data from an ArrayList (named cboCollection) in the settings in the combo box and vice versa.
private void Form1_Load(object sender, EventArgs e)
{
if (Settings.Default.cboCollection != null)
this.comboBox1.Items.AddRange(Settings.Default.cboCollection.ToArray());
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
ArrayList arraylist = new ArrayList(this.comboBox1.Items);
Settings.Default.cboCollection = arraylist;
Settings.Default.Save();
}
private int i;
private void button1_Click(object sender, EventArgs e)
{
this.comboBox1.Items.Add(i++);
}
source
share