In my C# WinForms program I have a treeview that only contains parent nodes (so, no childs) it is like a listbox but I needed it because of haveing differet properties of no
You can use BinaryFormatter to Serialize/Deserialize Nodes
public static void SaveTree(TreeView tree, string filename)
{
using (Stream file = File.Open(filename, FileMode.Create))
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(file, tree.Nodes.Cast<TreeNode>().ToList());
}
}
public static void LoadTree(TreeView tree, string filename)
{
using (Stream file = File.Open(filename, FileMode.Open))
{
BinaryFormatter bf = new BinaryFormatter();
object obj = bf.Deserialize(file);
TreeNode [] nodeList = (obj as IEnumerable<TreeNode>).ToArray();
tree.Nodes.AddRange(nodeList);
}
}