Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Save and Load TreeView content

0.00/5 (No votes)
13 Jun 2005 1  
A class that implements routines for saving and loading TreeView content using serialization.

Introduction

This is a class named LoadAndSave in the jhTreeViewTools namespace. I wrote it, because I needed to save and load the content of a TreeView in correct order including the Tags of each node. And I wanted to use serialization for that.

This is why I strongly required that there is nothing stored in the Node.Tag that isn't serializable because this will cause an error message. I am serializing the whole root-nodes, so everything that is stored in that Node and its children will be saved. I am still wondering why the ToolTip-text is not saved although it's also part of a Node!?

Details

There are only two public methods:

  • public static int saveTree(TreeView tree, string filename)
  • public static int loadTree(TreeView tree, string filename)

With those you can save and load the contents only by giving the TreeView control and the file name as arguments.

I use this class in my application in mostly the same way but I changed the main-descriptions of each method to the English language. The rest of the code-comments are in German because I haven't got the time to translate everything. Please try it and if there is anything that I may change or if you find mistakes in my code, please email me. Remind yourself that I am a C# beginner!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here