I use a treeview control in my windows application. In this application, there is a button that adds several nodes (root node & child node). Now I want to save this structure and use it when I open the application again.
How do I can do this?
I use a treeview control in my windows application. In this application, there is a button that adds several nodes (root node & child node). Now I want to save this structure and use it when I open the application again.
How do I can do this?
You need to do following things
1- Serilize your tree structor using BinaryFormatter , as a starting point see below
2- Once you got the Byte array , you can either save it to the database or in a file.
3- When you want to re-create the tree , you need to deserilize your saved data if it is in the databse , read the actual bytes and strore in a byte[] array or if it is in the file load the file and read all bytes into a Byte Array.
4- When you got the actual bytes , you can deserielize as per below code
here you can see the _list will contain the actual root node which was serilized earlier , now you got the data , you can re-construct your tree.