Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
namespace TreeViewControl
{
    [Serializable]
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string n = textBox1.Text;
            if (treeView1.SelectedNode == null)
            {
                treeView1.Nodes.Add(n, n);
            }
            else
            {
                treeView1.SelectedNode.Nodes.Add(n, n);
            }
        }
    }
  }

//somebody pls help how to serialize the given tree view control

What I have tried:

i have tried to export to xml file and all other my level approaches
Posted
Updated 28-Sep-16 8:40am
Comments
Member 12763843 28-Sep-16 7:11am    
can anybody help me with this??

Forms and controls are not serializable by just putting the [Serializable] attribute on them.

You have to write the code to grab the data you want from the controls and serialize that data yourself. Google for "Serialize treeview C#" for plenty of examples.
 
Share this answer
 
Comments
Maciej Los 28-Sep-16 14:24pm    
5ed!
As MSDN states:
Quote:
Serialization is the process of converting an object into a stream of bytes in order to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.
source: Serialization (C# )[^]

This means that you can serialize only objects (data), but not controls!

Depending on what you want to achieve, you may need to read this:
XML Serialization and Deserialization: Part-1[^]
XML Serialization and Deserialization: Part-2[^]
A Complete Sample of Custom Class Collection Serialization and Deserialization[^]
Serialize a parent-children hierarchy to XML[^]
 
Share this answer
 
Google[^]

If you have a specific issue with a specific approach then update your question accordingly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900