ISerializable class in TreeNode Tag => XML status ?

2 posts, 0 answers
  1. Bill Woodruff
    Bill Woodruff avatar
    4 posts
    Member since:
    Oct 2009

    Posted 07 Oct 2009 Link to this post

    Hi,

    I have read with interest all the threads and comments on this forum regarding "serialization," with particular attention to exchanges in early 2008 such as :

    http://www.telerik.com/community/forums/winforms/treeview/treeview-serializable.aspx#450955

    Where Peter of Telerik commented : "You could try to create your own class that implements ISerializable and contains the data you want to store in the Tag property" in response to a query about trying to save strings stored in the Tag of a TreeNode as XML.

    I've implemented a class that inherits from ISerializable, and has the mandatory Attributes and Security Permissions, and builds fine, but it breaks the TreeView XML parser or writer.

    In my opinion the lack of abilitiy to save strings in Node tags is a real deficit in the TreeView.

    Just curious if any changes are happening in this area of functionality. Obviously, as Peter demonstrated (see the linked article above), some objects, like DateTime are easily serializable. But Arrays of string, for example, while theoretically serializable, do not serialize ... but they do not cause an error, either.

    Appreciate any clear statement about what is and is not serializable at this time, and in any future planned changes.

    thanks, Bill

  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 13 Oct 2009 Link to this post

    Hello Bill,

    Please explain what do you mean by it breaks the TreeView XML parser or writer? I created a custom class which is decorated with the Serializable attribute, then I created an instance of it, and I assigned it to a node Tag and the XML file contains the necessary data. Here is the code:
    [Serializable]
    public class MySerializable
    {
        string mystr = "";
     
        public MySerializable()
        {
        }
     
        public string MyData
        {
            get
            {
                return this.mystr;
            }
     
            set
            {
                this.mystr = value;
            }
        }
    }

    Here is the instantiation and the call to SaveXML():
    this.radTreeView1.Nodes[1].Tag = new MySerializable();
    ((MySerializable)this.radTreeView1.Nodes[1].Tag).MyData = "ASDF";
    this.radTreeView1.SaveXML(@"C:\tv.xml", new Type[] {typeof(MySerializable)} );

    And lastly, here is the generated xml:

    <?xml version="1.0" encoding="utf-8" ?>
    - <TreeView xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ThemeName="ControlDefault" BackColor="Control">
      <Nodes Text="Node1" />
    - <Nodes Text="Node2">
    - <Tag xsi:type="MySerializable">
      <MyData>ASDF</MyData>
      </Tag>
      </Nodes>
      </TreeView>

    I am looking forward to your reply.

    Greetings,
    Victor
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top