Results 1 to 8 of 8

Thread: [RESOLVED] Treeview 3.5

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Resolved [RESOLVED] Treeview 3.5

    Hello friends how to serializes a System.Windows.Forms.TreeView, both node and .Tag information, and returns a byte array. same for it's opposite how to deserializes a byte array to a System.Windows.Form.TreeView.

    Thanks
    Shakti

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Treeview 3.5

    The TreeView is not serializable, so it can not be seiralized. The TreeNode class can be serialized however, but the TreeNodeCollection can not.
    Heres what I believe you'd need to do:

    Code:
        Private Sub SerializeTreeViewInfo(ByVal instance As TreeView, ByVal output As Stream)
            Dim formatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
            Dim nodes As New List(Of TreeNode)
    
            For i As Integer = 0 To instance.Nodes.Count - 1
                nodes.Add(instance.Nodes(i))
            Next
    
            formatter.Serialize(output, nodes)
    
            If instance.Tag.GetType().IsSerializable Then
                formatter.Serialize(output, instance.Tag)
            End If
        End Sub
    
        Private Sub DeserializeTreeViewInfo(ByVal instance As TreeView, ByVal input As Stream)
            Dim formatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
            Dim nodes As List(Of TreeNode)
    
            nodes = DirectCast(formatter.Deserialize(input), List(Of TreeNode))
    
            For i As Integer = 0 To nodes.Count - 1
                instance.Nodes.Add(nodes(i))
            Next
    
            If input.Position <> input.Length Then
                instance.Tag = formatter.Deserialize(input)
            End If
        End Sub
    This'll serialize the nodes and the tag, if possible directly to a stream...and not the TreeView itself.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Treeview 3.5

    Thanks I am looking code in c#

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Treeview 3.5

    Quote Originally Posted by shakti5385 View Post
    Thanks I am looking code in c#
    Oh..sorry about that, sometimes I confuse myself as I jump between the forums

    Code:
            private void SerializeTreeViewInfo(TreeView instance, System.IO.Stream output){
                System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                List<TreeNode> nodes = new List<TreeNode>();
    
                for(int i = 0; i < instance.Nodes.Count; i++)
                    nodes.Add(instance.Nodes[i]);
    
                formatter.Serialize(output, nodes);
    
                if(instance.Tag.GetType().IsSerializable)
                    formatter.Serialize(output, instance.Tag);
            }
    
            private void DeserializeTreeViewInfo(TreeView instance, System.IO.Stream input){
                System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                List<TreeNode> nodes;
    
                nodes = (List<TreeNode>)formatter.Deserialize(input);
    
                for(int i = 0; i < nodes.Count; i++)
                    instance.Nodes.Add(nodes[i]);
    
                if(input.Position != input.Length)
                    instance.Tag = formatter.Deserialize(input);
            }
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Treeview 3.5

    Thanks I will update you soon

  6. #6

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Treeview 3.5

    Hey thanks but here is some modification - A treeview is N-deep; this is 1-deep.

  7. #7
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Treeview 3.5

    How do you mean? My code should serialize all "levels" of nodes, no matter how deeply nested they are.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  8. #8

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: Treeview 3.5

    ok thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width