How to save the TreeView content
-
Hi there :) I am relative new in C# and I would like to save the content of the TreeView control in my Program. In other languages there I found something like
treeView->SaveToFile
.... or something like that. I tried already a little bit withSerialize
andBinaryFormatter
but it doesn't work at all. Could someone please help me ? :confused: -
Hi there :) I am relative new in C# and I would like to save the content of the TreeView control in my Program. In other languages there I found something like
treeView->SaveToFile
.... or something like that. I tried already a little bit withSerialize
andBinaryFormatter
but it doesn't work at all. Could someone please help me ? :confused:when you are saving the nodes on your treeview does it matter how they are saved? as in does order matter? or anything like that ? if none of that is of concern...(just guessing here) you could use a foreach statement to parse through each node, and then just save the text of the node. exsample :
foreach(TreeNode treenode in treeView.Nodes){ //MessageBox.Show(s.Text); just to see it. //now you have a treenode for each node in your treeview so all you have to do is write treenode.Name to a string[] or something and then write it to a file }
Good Luck Jesse M The Code Project Is Your Friend... -
Hi there :) I am relative new in C# and I would like to save the content of the TreeView control in my Program. In other languages there I found something like
treeView->SaveToFile
.... or something like that. I tried already a little bit withSerialize
andBinaryFormatter
but it doesn't work at all. Could someone please help me ? :confused: -
Rather than re-inventing the wheel, have a look at leppie's DUMmeter project here on CP - his code to persist the property grid settings using reflection could be adapted to persist any object, serializable or not.
Thanks Furty .. I downloaded that project and it looks good. I'll try it ... PS: Your FolderTreeView Project is excellent work I think !
-
when you are saving the nodes on your treeview does it matter how they are saved? as in does order matter? or anything like that ? if none of that is of concern...(just guessing here) you could use a foreach statement to parse through each node, and then just save the text of the node. exsample :
foreach(TreeNode treenode in treeView.Nodes){ //MessageBox.Show(s.Text); just to see it. //now you have a treenode for each node in your treeview so all you have to do is write treenode.Name to a string[] or something and then write it to a file }
Good Luck Jesse M The Code Project Is Your Friend...Hi Jesse. Yes the order and the Tag-Value of each node is needed -- I am able to save it like you say but I would have to store the Tag separately. I thought there must be a more elegant way to save the TreeView. Thatswhy I tried serialization .. but my knowledge of that is no that deep. :( .. Thanks for your help !!