Treeview Serializable?

7 posts, 0 answers
  1. John
    John avatar
    1 posts
    Member since:
    Oct 2007

    Posted 23 Oct 2007 Link to this post

    For simplistic Microsoft treeview serialization, you can do:
            Dim aList As New ArrayList
            Dim fs As New FileStream("D:\temp\test.dat", FileMode.Create)
            Dim f As New BinaryFormatter
            For Each node As TreeNode In Me.TreeView1.Nodes
                aList.Add(node)
            Next
            f.Serialize(fs, aList)
            fs.Close()

    I get an error attempting to serialize the RadTreeview control in a similar manner - telling me that the nodes collection is not serializable.
    Is the Winforms or Asp.net treeview control serializable, or is there a work around?
  2. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 23 Oct 2007 Link to this post

    Hi John,

    Thank you for writing.

    The RadTreeView itself is not serializable. Instead, we have implemented custom serialization.

    This allows for more control over the serialization (what gets serialized and how) and an even easier way for the user to serialize/deserialize the RadTreeView.

    We have provided an XML Serialization example in the Quick Start Framework. It contains the following example of using XML serialization with the RadTreeView:

    private void btnSaveFile_Click(object sender, EventArgs e) 
        SaveFileDialog saveFileDialog = new SaveFileDialog(); 
        saveFileDialog.AddExtension = true
        saveFileDialog.DefaultExt = ".xml"
        saveFileDialog.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*"
     
        if (saveFileDialog.ShowDialog() == DialogResult.OK) 
        { 
            this.radTreeView1.SaveXML(saveFileDialog.FileName); 
        } 

    Hope that helps. If you have any additional questions, please do not hesistate to contact us.

    Regards,
    Jordan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Kenneth Jackson
    Kenneth Jackson avatar
    60 posts
    Member since:
    Dec 2007

    Posted 29 Dec 2007 Link to this post

    I'm using the LoadXml / SaveXml methods to serialize/deserialize a treeview
    in my application. However - the save does NOT save all the data of
    the nodes , specifically its not saving tag data which is part of the nodes
    that im serializing . Is there a way to make this happen ? I've tried writing
    my own custom serialization but ofc get the error that the collection object
    is not marked for serialization.

    Thanks
  5. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 02 Jan 2008 Link to this post

    Hello Kenneth Jackson,

    Thank you for contacting us.

    In order for the object that is referenced by the Tag property to be serialized it must implement the ISerializable interface. For example, if we set the Tag property of a node to DateTime object we get the following XML after calling the SaveXML method:

    <Nodes Expanded="true" Text="Node1"
      <Nodes Expanded="true" Text="Node7"
        <Nodes Text="Node15" />  
        <Nodes Text="Node16" />  
      </Nodes> 
      <Nodes Expanded="true" Text="Node8"
        <Nodes Text="Node14" />  
      </Nodes> 
      <Nodes Text="Node9" />  
      <Tag xsi:type="xsd:dateTime">2008-01-02T10:20:49.8078636+02:00</Tag>  
    </Nodes> 
     

    I hope this helps. Please write us again if you have any additional questions.

    All the best,
    Jordan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Kenneth Jackson
    Kenneth Jackson avatar
    60 posts
    Member since:
    Dec 2007

    Posted 07 Jan 2008 Link to this post

    Thanks for your answer but i still can't seem to properly serialize my data.

    I need to be able to serialize string data from the tag.

    Now strings are marked SerializableAttribute but they do not implement
    the ISerializable interface . Does this mean i cannot serialiaze the string
    data in the tag property via your Load/SaveXML methods ?
  7. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 07 Jan 2008 Link to this post

    Hello Kenneth Jackson,

    Thank you for writing.

    Sorry for the inconvenience. This is necessary in order to ensure that the contents of the Tag property can be successfully serialized. You could try to create your own class that implements ISerializable and contains the data you want to store in the Tag property.

    Please contact us again if you have any other questions.

    Kind regards,
    Peter
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. Kenneth Jackson
    Kenneth Jackson avatar
    60 posts
    Member since:
    Dec 2007

    Posted 08 Jan 2008 Link to this post

    Thanks for the help
Back to Top
UI for WinForms is Visual Studio 2017 Ready