Home All Groups Group Topic Archive Search About

How to serialize a custom collection at design time

Author
15 Dec 2006 2:44 PM
Mark Collard
I've noticed that you can add TreeNode's to a TreeView control at design.
When you do, it serializes the TreeNode's in the InitializeComponent
procedure using the AddRange method on the TreeNodeCollection class.

E.g.

this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
    new System.Windows.Forms.TreeNode("Node0"),
    new System.Windows.Forms.TreeNode("Node1"),
    new System.Windows.Forms.TreeNode("Node2"),
    new System.Windows.Forms.TreeNode("Node3"),
    new System.Windows.Forms.TreeNode("Node4")});


I'm currently writing a custom control, that also has a custom collection
that you can add and remove items to add design time. I've added a AddRange
method to the custom collection, but I can't work out how to serialize the
collection (like the TreeNodeCollection class) so that it uses the AddRange
method (like in the above example).

Can someone please show me how to serialize a custom collection into the
InitializeComponent procedure so that it uses the AddRange (like in the above
example)?

Thank you

Regards
Mark

Author
15 Dec 2006 3:44 PM
sloan
You might find some help at my post:

9/21/2005
XmlSerialization with IDictionary and CollectionBase Objects

http://sholliday.spaces.live.com/blog/


Show quoteHide quote
"Mark Collard" <Mark Coll***@discussions.microsoft.com> wrote in message
news:305F6501-CCCB-4071-A9C6-CE55AB38180B@microsoft.com...
> I've noticed that you can add TreeNode's to a TreeView control at design.
> When you do, it serializes the TreeNode's in the InitializeComponent
> procedure using the AddRange method on the TreeNodeCollection class.
>
> E.g.
>
> this.treeView1.Nodes.AddRange(new System.Windows.Forms.TreeNode[] {
> new System.Windows.Forms.TreeNode("Node0"),
> new System.Windows.Forms.TreeNode("Node1"),
> new System.Windows.Forms.TreeNode("Node2"),
> new System.Windows.Forms.TreeNode("Node3"),
> new System.Windows.Forms.TreeNode("Node4")});
>
>
> I'm currently writing a custom control, that also has a custom collection
> that you can add and remove items to add design time. I've added a
AddRange
> method to the custom collection, but I can't work out how to serialize the
> collection (like the TreeNodeCollection class) so that it uses the
AddRange
> method (like in the above example).
>
> Can someone please show me how to serialize a custom collection into the
> InitializeComponent procedure so that it uses the AddRange (like in the
above
> example)?
>
> Thank you
>
> Regards
> Mark

Bookmark and Share