Treeview Control - and saving it's nodes...

G

garyusenet

Hi All,

I'm eagerly anticipating what you have to say on something that's
stumped me over the weekend. I'm writing a small application which
utilises a treeview control. I've figured out how to programatically
add nodes to it, but everytime the program is exited the treeview
control resets itself.

I looked for a save method or something similair but there doesn't seem
to be one. I have found the copyto method, and figured out how to copy
the treeview collection to an array however!

So I thought i could write this array to a file, and read it at runtime
to populate the treeview, however when I enumerate the array I only get
the parant nodes. And when I use the rank method It tells me the array
is one dimensional.

So my question is twofold really. One, am I going about this the right
way or is there a better way to save the treeview collection? And two,
how do I copy the entire treeview collection to an array, and not just
the parant nodes?

Many thanks, and in anticipation!

Gary.
 
G

garyusenet

In case anyone is reading this and needs help with the treeview control
and saving it's content. I have found the answer. Firstly to get the
entire tree view, you first create an 'arraylist' and then add all the
nodes to the treeview. al in the code below is the name of an
arraylist.

foreach (TreeNode tn in tree.Nodes)
{
// add every treenode in tree.nodes to the array
al.Add(tn);
}

and how do you save this to a file? The answer is something called
serialisation, it's exactly the answer what I needed - so read up on it
if you need to save a treeview. It lets you write a complex object to a
file.

Nice when it all clicks into place!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top