In the application settings I have a setting called Locations and the type is a System.Collections.Specialized.StringCollection.
I also have a textbox and a button that are supposed to add values to the StringCollection.
After entering the value into the textbox, the value is supposed to be added into a listbox and into the StringCollection. The code for adding a new value to the listbox and StringCollection is as follow:
string newPrintLocation = tbAddPrintLocation.Text;
if (lbPrintLocations.Items.Contains(newPrintLocation) == false)
{
lbPrintLocations.Items.Add(newPrintLocation);
Properties.Settings.Default.Locations.Add(newPrintLocation);
cbPrintLocation.Items.Add(newPrintLocation);
tbAddPrintLocation.Clear();
}
The goal is when the user restarts the form the values are added back into the listbox. Currently this is the code that I use to try to achieve that:
foreach (var item in Properties.Settings.Default.Locations)
{
lbPrintLocations.Items.Add(item);
}
The problem is that only the first value gets added to the listbox but none of the rest. At this point I have no idea what I am doing wrong. So I was wondering if someone could help me out or point me to the right direction.
All help is greatly appreciated.
Cheers,
Quartermain.