I have a program with a combo box, a list for that box and a string.
The string is created from user input via a text box and is saved each time the program closes. So if I type "Input Text" then close and open the program the combo box will have a list containing 1 string which displays "Input Text"
The issue is I want to keep adding to the list with new information but at the moment its just constantly overriding what I put in last time.
How do I add to my list with a new item each time the string is different?
private void Form1_Load(object sender, EventArgs e)
{
//Load Settings
saveLocationTextBox.Text = MySettings.Default["SaveSaveLocationText"].ToString();
List<string> list = new List<string>();
list.Add(saveLocationTextBox.Text);
comboBox.DataSource = list;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
//Save User Input
MySettings.Default["SaveSaveLocationText"] = saveLocationTextBox.Text;
MySettings.Default.Save();
}
Form1_Loadyou should add the new string to that saved list of strings rather than creating a new list and adding it into that list. Because each time you are creating a new list from scratch and you only add the new string into it.