Click here to Skip to main content
Click here to Skip to main content

Save and Load TreeView content

, 13 Jun 2005
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

j-hannemann
Database Developer
Germany Germany
I am programming more or less since I was 15 years.
It started with BASIC and during school I did
a lot Pascal programs for MS DOS.
After that I came to visual Windows programming and coded a lot in Delphi and later in C# .NET.
I made also some excursions in C and C++.
 
I also like Perl, Python and other scripting languages.
After a long break not programming anything, the last approx. 5-6 years I am only working with Java and SQL.
 
New for me is Objective-C - I am starting to get involved into Mac Programming Smile | :)

Comments and Discussions

 
GeneralMy vote of 5 Pinmember Gun Gun Febrianza14-Nov-14 23:30 
QuestionThanks! PinmemberMember 1088107512-Jun-14 9:47 
QuestionGreat code Pinmembercountrysideflair19-Jul-11 10:26 
GeneralCan't save stateimageindex using u'r code Pinmembermr.nothing6-May-11 6:32 
AnswerRe: Can't save stateimageindex using u'r code Pinmemberj-hannemann9-May-11 5:52 
GeneralSaving to registry using Binary Stream Pinmembermsanjay7530-Jul-09 5:53 
GeneralGreat code! Pinmemberluk1413316-Feb-09 1:05 
Generalproblem while saving Pinmemberreji.sukesan10-Jul-07 15:59 
Questionhow to implemt in project Pinmemberikkevd7-Apr-07 4:47 
AnswerRe: how to implemt in project Pinmemberj-hannemann14-May-07 20:14 
GeneralThank You PinmemberAniket Salunkhe27-Nov-06 4:22 
QuestionRe: Thank You ( 'DataGridViewRow is not marked as Serializable') [modified] PinmemberAniket Salunkhe28-Nov-06 3:30 
GeneralNice One!! PinmemberJ101uk24-Sep-06 11:10 
GeneralChildnode Problem PinmemberDavid Rider5-Feb-06 7:37 
GeneralGood Job PinmemberPHDENG8124-Jan-06 5:31 
GeneralBUG!!! Pinmemberlior654@hotmail.com12-May-05 8:16 
GeneralRe: BUG!!! Pinmemberj-hannemann14-Jun-05 8:51 
GeneralA couple suggestions... Pinmember.S.Rod.31-Mar-03 0:28 
GeneralRe: A couple suggestions... Pinmemberj-hannemann31-Mar-03 2:10 
GeneralRe: A couple suggestions... Pinmember.S.Rod.31-Mar-03 2:40 
GeneralRe: A couple suggestions... Pinmemberj-hannemann31-Mar-03 4:03 
GeneralRe: A couple suggestions... Pinmember.S.Rod.31-Mar-03 4:14 
GeneralRe: A couple suggestions... PinmemberMarc Clifton31-Mar-03 11:30 
GeneralRe: A couple suggestions... Pinmemberpatnsnaudy8-Apr-03 4:15 
GeneralRe: A couple suggestions... PinmemberMarc Clifton8-Apr-03 10:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 14 Jun 2005
Article Copyright 2003 by j-hannemann
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid