Great code. I did some playing around with it but there seems to be just a small problem in that I can't save it to SQL Server. There isn't a comparable System.Object type for the nodes which actually translates to a treenode collection. Any ideas on how to resolve or where to look?
Thanks.
>Here is how you can do it.
>
>
> DataTable loDT = new DataTable();
> System.Type myDataType;
> myDataType = System.Type.GetType("System.Object");
> DataColumn loCL = new DataColumn("myColumn",myDataType);
> loDT.Columns.Add(loCL);
> DataRow loROW = loDT.NewRow();
> loROW[0] = this.treeView1.Nodes[0];
> loDT.Rows.Add(loROW);
>
> TreeNode loNewNode = (TreeNode) ((TreeNode) loDT.Rows[0][0]).Clone();
> loNewNode.Text = "New Node";
> this.treeView2.Nodes.Add(loNewNode);
>
>
>I am adding new node to another TreeView control. You can add it to the same one after removing all nodes from it.
>
>>It appears that your code will allow the save of the nodes but I can't seem to find a way to convert it back to a value the treeview will like. I am using Option strict on which won't convert it implicitly.
>>
>>
>>
>>>I guess you can store any kind of "object" to a column in a data table. I tried to store Nodes collection in the following example. In the same fashin, you can either store XML as String of Stream.
>>>
>>>
>>>DataTable loDT = new DataTable();
>>>DataColumn loCL = new DataColumn();
>>>loDT.Columns.Add(loCL);
>>>DataRow loROW = loDT.NewRow();
>>>loROW[0] = this.treeView1.Nodes;
>>>loDT.Rows.Add(loROW);
>>>
>>>
>>>>Has anyone figured out how to generate a xml stream to a column in a dataset instead of to a file?
>>>>
>>>>I am saving treeview information to an xml document and do to customer contraints, I need to save the xml to a column in a dataset and be able to read it back to recreate the treeview.
>>>>
>>>>I am using the following code in VB.Net to accomplish part of the process although it only writes to a file.
>>>>
>>>>
>>>>
>>>> Dim formatter As SoapFormatter = New SoapFormatter()
>>>> Dim stream As Stream = New FileStream("c:\Free.xml", FileMode.Create, FileAccess.Write, FileShare.None)
>>>>
>>>> Dim root As New TreeNode()
>>>> Dim node As TreeNode
>>>> For Each node In treForceStructure.Nodes
>>>> root.Nodes.Add(CType(node.Clone(), TreeNode))
>>>> Next node
>>>> formatter.Serialize(stream, root)
>>>> stream.Close()
>>>>
>>>>
>>>>
>>>>Any ideas on how to accomplish this? I can't seem to find any info on it.
>>>>
>>>>Thanks,
>>>>Pat.
Patrick L. Stovall
Senior Architect/Developer
MCP - C#
VeroQuest
P.O.Box 7216
Kalispell, MT 59904