As in previously stated answers, dynamically inserted elements will disappear if the program restarts. This is simply because they are not recorded to a physical drive and will be removed as soon as the garbage collector realizes their work is done.
Simplest way to avoid this is to write contents of a combobox to a text file (if you do not want to meddle with databases) and save that file (as comboboxName.txt, for example). The second time program opens and shows form2, first add the items in the text document to the combobox.
StringBuilder sb = new StringBuilder();
foreach(var item in ComboboxName.Items)
{
sb.AppendLine(item.ToString());
}
string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
using(StreamWriter _sw = new StreamWriter(folderPath+@"\ComboboxName.txt"))
{
_sw.Write(sb.ToString());
}
string filePath=Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)+@"\ComboboxName.txt";
using (StreamReader sr = new StreamReader(filePath)
{
String line;
while ((line = sr.ReadLine()) != null)
{
ComboboxName.Items.Add(line);
}
}
One point is, if you try to save the file into sensitive folders, your program might need to be executed as elevated (i.e. run as administrator)
Of course these codes are almost pseudocodes. For better performance compare existing lines in the text file and combobox and write/delete only if necessary.