Click here to Skip to main content
Licence 
First Posted 30 Mar 2003
Views 106,611
Bookmarked 35 times

Save and Load TreeView content

By | 13 Jun 2005 | Article
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

About the Author

j-hannemann

Database Developer

Germany Germany

Member

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 | :)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionGreat code Pinmembercountrysideflair9:26 19 Jul '11  
GeneralCan't save stateimageindex using u'r code Pinmembermr.nothing5:32 6 May '11  
AnswerRe: Can't save stateimageindex using u'r code Pinmemberj-hannemann4:52 9 May '11  
GeneralSaving to registry using Binary Stream Pinmembermsanjay754:53 30 Jul '09  
GeneralGreat code! Pinmemberluk141330:05 16 Feb '09  
Generalproblem while saving Pinmemberreji.sukesan14:59 10 Jul '07  
Questionhow to implemt in project Pinmemberikkevd3:47 7 Apr '07  
AnswerRe: how to implemt in project Pinmemberj-hannemann19:14 14 May '07  
GeneralThank You PinmemberAniket Salunkhe3:22 27 Nov '06  
QuestionRe: Thank You ( 'DataGridViewRow is not marked as Serializable') [modified] PinmemberAniket Salunkhe2:30 28 Nov '06  
GeneralNice One!! PinmemberJ101uk10:10 24 Sep '06  
GeneralChildnode Problem PinmemberDavid Rider6:37 5 Feb '06  
GeneralGood Job PinmemberPHDENG814:31 24 Jan '06  
GeneralBUG!!! Pinmemberlior654@hotmail.com7:16 12 May '05  
GeneralRe: BUG!!! Pinmemberj-hannemann7:51 14 Jun '05  
GeneralA couple suggestions... Pinmember.S.Rod.23:28 30 Mar '03  
GeneralRe: A couple suggestions... Pinmemberj-hannemann1:10 31 Mar '03  
GeneralRe: A couple suggestions... Pinmember.S.Rod.1:40 31 Mar '03  
GeneralRe: A couple suggestions... Pinmemberj-hannemann3:03 31 Mar '03  
GeneralRe: A couple suggestions... Pinmember.S.Rod.3:14 31 Mar '03  
GeneralRe: A couple suggestions... PinmemberMarc Clifton10:30 31 Mar '03  
GeneralRe: A couple suggestions... Pinmemberpatnsnaudy3:15 8 Apr '03  
GeneralRe: A couple suggestions... PinmemberMarc Clifton9:56 8 Apr '03  

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.

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