List View items - exporting and importing data
-
Hi. I have a list view with about 4000 items (with 7 subitems, too) and I'd like to 'export', ie. save all the data, to a tab-separated file, so the data can be reloaded later. The problem is, that the saving and loading process using, for example: (Save) (...) foreach(ListViewItem lvi in this.listView1.Items) { string line = ""; line += lvi.Text; for(int i=1;i
-
Hi. I have a list view with about 4000 items (with 7 subitems, too) and I'd like to 'export', ie. save all the data, to a tab-separated file, so the data can be reloaded later. The problem is, that the saving and loading process using, for example: (Save) (...) foreach(ListViewItem lvi in this.listView1.Items) { string line = ""; line += lvi.Text; for(int i=1;i
Hi, what you want to do is called serialization. Serialization is saving an object's state to a stream so its state can be transported or saved and later restored. You suggested a tab separated text file, which is nice since the file is easily read and understood by other applications, however binary files are faster. If format don't mattter to you, I would suggest binary format. BinaryFormatter.Serialize Method is the method you use for binary serialization. The problem will be for you that a listview control or ListViewItemCollection object do not support serialization. To be able to serialize an object, the object's class needs to be either marked with the Serializable attribute or implement the ISerializable interface. The class ArrayList however is marked Serializable attribute and it's pretty easy to construct an arraylist from a listview control. Good luck and feel free to check my C# blog, Patric