I have 2 Windows Forms. In the second form I have a few checkedListBoxex and my problem is that when I'm trying to get those checks and save it for the next time, it's not saving them, maybe I did a small mistake somewhere. I think it should be problem with load.
My code:
public partial class Form2 : Form
{
readonly Form1 form1;
StringCollection collectionOfTags = new StringCollection();
public Form2(Form1 owner)
{
form1 = owner;
InitializeComponent();
InitializeSecondForm();
}
private void InitializeSecondForm()
{
this.Height = Properties.Settings.Default.SecondFormHeight;
this.Width = Properties.Settings.Default.SecondFormWidth;
this.Location = Properties.Settings.Default.SecondFormLocation;
this.collectionOfTags = Properties.Settings.Default.DICOMTagSettings;
this.FormClosing += SecondFormClosingEventHandler;
this.StartPosition = FormStartPosition.Manual;
}
private void SecondFormClosingEventHandler(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.SecondFormHeight = this.Height;
Properties.Settings.Default.SecondFormWidth = this.Width;
Properties.Settings.Default.SecondFormLocation = this.Location;
Properties.Settings.Default.DICOMTagSettings = this.collectionOfTags;
Properties.Settings.Default.Save();
}
private void button1_Click(object sender, EventArgs e)
{
foreach (string s in checkedListBox1.CheckedItems)
Properties.Settings.Default.DICOMTagSettings.Add(s);
collectionOfTags = Properties.Settings.Default.DICOMTagSettings;
foreach (string s in checkedListBox2.CheckedItems)
Properties.Settings.Default.DICOMTagSettings.Add(s);
collectionOfTags = Properties.Settings.Default.DICOMTagSettings;
foreach (string s in checkedListBox3.CheckedItems)
Properties.Settings.Default.DICOMTagSettings.Add(s);
collectionOfTags = Properties.Settings.Default.DICOMTagSettings;
this.Close();
}
This is how it looks in settings.
This one I added just by typing it.
When I'm debugging, I can see that I have some items there, but it's not saving them there.