I'm serializing a TreeNode
using this function :
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());
}
}
when I deserialize using this function :
public static TreeView LoadTree(string filename)
{
TreeView tree = new TreeView();
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);
}
return tree;
}
I didn't get the nodes imageindex
I get the value -1
for all nodes imageindex !
Why ?