Click here to Skip to main content
12,452,344 members (58,393 online)
Click here to Skip to main content
Add your own
alternative version

Stats

130.2K views
2.9K downloads
37 bookmarked
Posted

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

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralMy vote of 5 Pin
Gun Gun Febrianza14-Nov-14 22:30
member Gun Gun Febrianza14-Nov-14 22:30 
QuestionThanks! Pin
Member 1088107512-Jun-14 8:47
memberMember 1088107512-Jun-14 8:47 
QuestionGreat code Pin
countrysideflair19-Jul-11 9:26
membercountrysideflair19-Jul-11 9:26 
GeneralCan't save stateimageindex using u'r code Pin
mr.nothing6-May-11 5:32
membermr.nothing6-May-11 5:32 
AnswerRe: Can't save stateimageindex using u'r code Pin
j-hannemann9-May-11 4:52
memberj-hannemann9-May-11 4:52 
GeneralSaving to registry using Binary Stream Pin
msanjay7530-Jul-09 4:53
membermsanjay7530-Jul-09 4:53 
GeneralGreat code! Pin
luk1413316-Feb-09 0:05
memberluk1413316-Feb-09 0:05 
Generalproblem while saving Pin
reji.sukesan10-Jul-07 14:59
memberreji.sukesan10-Jul-07 14:59 
Questionhow to implemt in project Pin
ikkevd7-Apr-07 3:47
memberikkevd7-Apr-07 3:47 
AnswerRe: how to implemt in project Pin
j-hannemann14-May-07 19:14
memberj-hannemann14-May-07 19:14 
GeneralThank You Pin
Aniket Salunkhe27-Nov-06 3:22
memberAniket Salunkhe27-Nov-06 3:22 
QuestionRe: Thank You ( 'DataGridViewRow is not marked as Serializable') [modified] Pin
Aniket Salunkhe28-Nov-06 2:30
memberAniket Salunkhe28-Nov-06 2:30 
GeneralNice One!! Pin
J101uk24-Sep-06 10:10
memberJ101uk24-Sep-06 10:10 
GeneralChildnode Problem Pin
David Rider5-Feb-06 6:37
memberDavid Rider5-Feb-06 6:37 
GeneralGood Job Pin
PHDENG8124-Jan-06 4:31
memberPHDENG8124-Jan-06 4:31 
GeneralBUG!!! Pin
lior654@hotmail.com12-May-05 7:16
memberlior654@hotmail.com12-May-05 7:16 
GeneralRe: BUG!!! Pin
j-hannemann14-Jun-05 7:51
memberj-hannemann14-Jun-05 7:51 
GeneralA couple suggestions... Pin
.S.Rod.30-Mar-03 23:28
member.S.Rod.30-Mar-03 23:28 
GeneralRe: A couple suggestions... Pin
j-hannemann31-Mar-03 1:10
memberj-hannemann31-Mar-03 1:10 
GeneralRe: A couple suggestions... Pin
.S.Rod.31-Mar-03 1:40
member.S.Rod.31-Mar-03 1:40 
GeneralRe: A couple suggestions... Pin
j-hannemann31-Mar-03 3:03
memberj-hannemann31-Mar-03 3:03 
GeneralRe: A couple suggestions... Pin
.S.Rod.31-Mar-03 3:14
member.S.Rod.31-Mar-03 3:14 
GeneralRe: A couple suggestions... Pin
Marc Clifton31-Mar-03 10:30
memberMarc Clifton31-Mar-03 10:30 
GeneralRe: A couple suggestions... Pin
patnsnaudy8-Apr-03 3:15
memberpatnsnaudy8-Apr-03 3:15 
GeneralRe: A couple suggestions... Pin
Marc Clifton8-Apr-03 9:56
memberMarc Clifton8-Apr-03 9:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web01 | 2.8.160826.1 | Last Updated 14 Jun 2005
Article Copyright 2003 by j-hannemann
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid