473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Serialize a tree?

Hello experts,

I'm a total C# noob with a total C# noob question.

I've been Serializing in C++ (MFC) and writing data to std::fstreams for
quite some time, so maybe I'm not understanding this different
technique, or reading too much into it, or not enough: but, I'm not
quite wrapping my brain around serialization in C#.

Here's what I have and here's what I want to do:

I have a [Serializable] abstract class, "Bead". Derived from Bead is a
family of Bead-Types - RedBead, BlueBead, GreenBead, OrangeBead,
ClearBead, etc - all of which are [Serializable].
Over here, I have a TreeView object. Each TreeNode of the TreeView
object has a Bead object assigned to it, via the Tag property.

I want to save the Bead hierarchy as it appears in the tree.

Now, if I were to Serialize the TreeView itself, would it properly save
each attached Bead when it does so? Do I have to make each Bead type
serializable, and define serialize/deserialize methods for them?
I dont mind traversing the tree and having each bead serialize and
deserialize itself, (which was what I was going to do), but I'm
wondering if this "Save the whole darned Tree" approach would work.

Any thoughts?

TIA.

--
Bryan
Nov 17 '05 #1
3 7541
You really want to serialize the control?
Is there a reason you wouldn't just save the data?

This helps simulate data binding to the windows
forms treeview control (it doesn't natively support this).

http://www.eggheadcafe.com/articles/...atabinding.asp

--
Robbe Morris - 2004/2005 Microsoft MVP C#

Earn money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp

"Toxick" <to****@e2.com> wrote in message
news:Xn***************************@207.46.248.16.. .
Hello experts,

I'm a total C# noob with a total C# noob question.

I've been Serializing in C++ (MFC) and writing data to std::fstreams for
quite some time, so maybe I'm not understanding this different
technique, or reading too much into it, or not enough: but, I'm not
quite wrapping my brain around serialization in C#.

Here's what I have and here's what I want to do:

I have a [Serializable] abstract class, "Bead". Derived from Bead is a
family of Bead-Types - RedBead, BlueBead, GreenBead, OrangeBead,
ClearBead, etc - all of which are [Serializable].
Over here, I have a TreeView object. Each TreeNode of the TreeView
object has a Bead object assigned to it, via the Tag property.

I want to save the Bead hierarchy as it appears in the tree.

Now, if I were to Serialize the TreeView itself, would it properly save
each attached Bead when it does so? Do I have to make each Bead type
serializable, and define serialize/deserialize methods for them?
I dont mind traversing the tree and having each bead serialize and
deserialize itself, (which was what I was going to do), but I'm
wondering if this "Save the whole darned Tree" approach would work.

Any thoughts?

TIA.

--
Bryan

Nov 17 '05 #2
> You really want to serialize the control?
Is there a reason you wouldn't just save the data?


No, theres no reason, and in fact, I actually had a solution in mind
when I wrote the original post, but if there's something built in to
save a tree in a tree format it'll save me some work.
I'm not so much concerned with saving the control, as I am saving the
data attached to the tag properites of the nodes, and keeping the
*hierarchy* in tact.

I want to store the beads of data in a hierarchical fashion, and the
tree control provides a convenient means of structure, display and
(hopefully) storage. I had actually started to write a Tree object,
which was just a container, but then I realized, duh - the TreeView
already has the structure I need. I'll just use that as the data
container.
But I still need to save the data.
I'm going to read the article you posted - and thank you - but upon an
initial skim, I'm not sure if it explains much more than I already have
done - that is using the tag attribute of the TreeNode objects to pin
my objects to the tree. Which I've done and which works.

Am I to infer from your post that deriving a "BeadTreeView" class from
the TreeView and labelling it [Serializable] and then serializing it
(perhaps with a BinaryFormatter object) will not work.

Nov 17 '05 #3
The thing that that article does is keep the DataRow in each .Tag
in sync with the DataSet and the TreeView. If you change the
order in the tree, drag and drop nodes, delete nodes, add nodes, etc...

The class and the DataSet are all kept in sync automatically.

As far as serializing the control? I just didn't see the logic
in trying or a business case for doing so.

--
Robbe Morris - 2004/2005 Microsoft MVP C#

Earn money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp

<ec*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
You really want to serialize the control?
Is there a reason you wouldn't just save the data?


No, theres no reason, and in fact, I actually had a solution in mind
when I wrote the original post, but if there's something built in to
save a tree in a tree format it'll save me some work.
I'm not so much concerned with saving the control, as I am saving the
data attached to the tag properites of the nodes, and keeping the
*hierarchy* in tact.

I want to store the beads of data in a hierarchical fashion, and the
tree control provides a convenient means of structure, display and
(hopefully) storage. I had actually started to write a Tree object,
which was just a container, but then I realized, duh - the TreeView
already has the structure I need. I'll just use that as the data
container.
But I still need to save the data.
I'm going to read the article you posted - and thank you - but upon an
initial skim, I'm not sure if it explains much more than I already have
done - that is using the tag attribute of the TreeNode objects to pin
my objects to the tree. Which I've done and which works.

Am I to infer from your post that deriving a "BeadTreeView" class from
the TreeView and labelling it [Serializable] and then serializing it
(perhaps with a BinaryFormatter object) will not work.

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: vince | last post by:
Can I add (append) to an xml file that already contains a serialized object, and be able to deserialize to either or both objects from the same file...??? How is this done...?? thanks, vince
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
1
by: alexis rzewski | last post by:
I have a design in place for a .NET app coded in C# in which the business object drives the appearence of the UI and when the business object experiences a change, it notifies the various UIs via...
2
by: sweety | last post by:
Hi, Want to write the following struecture in to a file insted of writing each data, how the serialize support for this. Would be great if sample code or the interface info provided. ...
18
by: yusuf | last post by:
I basically want to be able to store and retrieve a tree structure in greasemonkey. Unfortunately the GM_setValue and GM_getValue functions only take string key value pairs. Is there a native...
1
by: Lamis | last post by:
Hi, I have a tree structured object. Each node of the tree has a haschtable. I need to XML serialize my object... what is the best way to xml-serialize haschtable -- LZ
4
by: greenman | last post by:
Hello, Is there a chance to serialize a selection/range object (holding the selected by the user text fragment) on a webpage, so that I could deserialize it later on this site and make this...
2
by: Andy B | last post by:
Is it possible to serialize to xml a dictionary<string, stringobject in ..net 3.5?
8
by: Andy B | last post by:
I have the following code in a default.aspx web form page_load event. There seems to be a problem with line 5 (NewsArticle.Date = line). //create a news article NewsArticle NewsArticle = new...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.