This is a migrated thread and some comments may be shown as answers.

Treeview Serializable?

6 Answers 312 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 23 Oct 2007, 05:37 AM
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?

6 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 23 Oct 2007, 08:18 AM
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
0
Kenneth Jackson
Top achievements
Rank 1
answered on 29 Dec 2007, 09:49 PM
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
0
Jordan
Telerik team
answered on 02 Jan 2008, 09:44 AM
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
0
Kenneth Jackson
Top achievements
Rank 1
answered on 07 Jan 2008, 08:28 AM
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 ?
0
Peter
Telerik team
answered on 07 Jan 2008, 12:10 PM
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
0
Kenneth Jackson
Top achievements
Rank 1
answered on 08 Jan 2008, 07:42 PM
Thanks for the help
Tags
Treeview
Asked by
John
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Kenneth Jackson
Top achievements
Rank 1
Peter
Telerik team
Share this question
or