Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to save the TreeView content

How to save the TreeView content

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    j hannemann
    wrote on last edited by
    #1

    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 with Serialize and BinaryFormatter but it doesn't work at all. Could someone please help me ? :confused:

    J F 2 Replies Last reply
    0
    • J j hannemann

      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 with Serialize and BinaryFormatter but it doesn't work at all. Could someone please help me ? :confused:

      J Offline
      J Offline
      jtmtv18
      wrote on last edited by
      #2

      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...

      J 1 Reply Last reply
      0
      • J j hannemann

        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 with Serialize and BinaryFormatter but it doesn't work at all. Could someone please help me ? :confused:

        F Offline
        F Offline
        Furty
        wrote on last edited by
        #3

        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.

        J 1 Reply Last reply
        0
        • F Furty

          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.

          J Offline
          J Offline
          j hannemann
          wrote on last edited by
          #4

          Thanks Furty .. I downloaded that project and it looks good. I'll try it ... PS: Your FolderTreeView Project is excellent work I think !

          1 Reply Last reply
          0
          • J jtmtv18

            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...

            J Offline
            J Offline
            j hannemann
            wrote on last edited by
            #5

            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 !!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups