Adding a TreeNodeCollection to TreeView

C

Chuck Bowling

I have a serialized TreeNodeCollection that I want to initialize a TreeView
with. Is there a simple assignment I can use for this or do I have to
iterate thru the collection and add individual Nodes?
 
F

Frans Bouma [C# MVP]

Chuck said:
I have a serialized TreeNodeCollection that I want to initialize a TreeView
with. Is there a simple assignment I can use for this or do I have to
iterate thru the collection and add individual Nodes?

Sorry if I sound rude, but did you even try something out/checked the
documentation before asking this question? THe reason for this is that
the treeview.Nodes collection has an AddRange() method which will make
adding the collection you have a 1 liner. :)

Btw, a serialized collection, you mean a DEserialized collection, or a
serialized collection in binary format/soap format/xml?

Frans.
 
C

Chuck Bowling

Frans Bouma said:
Sorry if I sound rude, but did you even try something out/checked the
documentation before asking this question? THe reason for this is that the
treeview.Nodes collection has an AddRange() method which will make adding
the collection you have a 1 liner. :)

Btw, a serialized collection, you mean a DEserialized collection, or a
serialized collection in binary format/soap format/xml?

As a matter of fact, it did sound a little rude. I scoured the docs and the
internet for over an hour looking for a solution. FYI, I also tried using
AddRange before posting and couldn't get it to work. My solution didn't use
AddRange at all...
 
F

Frans Bouma [C# MVP]

Chuck said:
As a matter of fact, it did sound a little rude. I scoured the docs and the
internet for over an hour looking for a solution. FYI, I also tried using
AddRange before posting and couldn't get it to work. My solution didn't use
AddRange at all...

You tried AddRange but it didn't work, my obvious question then is:
how didn't it work? Did you get an exception, compile error, or weren't
any nodes added?

Also, you still haven't answered what a serialized TreeNodeCollection
is :) Is that an xml file, a serialized blob from the bin formatter or a
DEserialized object?

Frans.
 
C

Chuck Bowling

Frans Bouma said:
You tried AddRange but it didn't work, my obvious question then is: how
didn't it work? Did you get an exception, compile error, or weren't any
nodes added?

Also, you still haven't answered what a serialized TreeNodeCollection is
:) Is that an xml file, a serialized blob from the bin formatter or a
DEserialized object?

If I recall, I tried to use AddRange directly as in:

TreeNodeCollection c = (TreeNodeCollection) formatter.Deserialize(stream);
treeView.AddRange(c);

or something close. Not sure now as I've moved beyond. The error is that
TreeNodeCollections are not serializable I think.

A TreeNodeCollection is a collection returned by the TreeView.Nodes
property. I solved the problem by iterating thru the TreeNodeCollection and
putting nodes in an ArrayList. That solved all the serialization problems.
 

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