Forget text files! Use XML files. This is after all 2008!
You can do this easy by :
//this code isn't tested but u'll get the idéa
Code:
try{
XmlDocument MyXML = new XmlDocument();
XmlElement MyROOT;
XmlElement MyElement;
//creates a root for you
ROOT = MyXML.CreateElement("mydata");
MyXML.AppendChild(ROOT);
//adds your data inside the root
foreach(string sItem in comboBox1.Items){
MyElement = MyXML.CreateElement("DATA");//creates a node "DATA"
MyElement.InnerText = sItem;//puts your item text|data inside the "DATA" node
ROOT.InsertAfter(MyElement, ROOT.LastChild);
}
//save your XML
MyXML.Save("c:\somefile.xml");
}
catch(Exception e){
Console.Write( e.ToString() );
}
Once saving XML, open your file with notepad or IE, it should look like this inside :
<mydata>
<DATA>text of item in combo box</DATA>
<DATA>text of item in combo box</DATA>
<DATA>text of item in combo box</DATA>
</mydata>