Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

way to save content of treeview

Hi all,
has anyone tried to save the content of a treeview (node structure) to a file (XML, txt,...). Of course, it has to be read from the next time the app is launched again :-)
I found some source code to load an XML containing a tv structure into the control, but the other way around seems more difficult.
By default the treeview class offers no means to perform persistent action.
Any help, tips, tricks on this topic would be very welcome.

Saturday, December 6, 2003

You need to walk the Node hierarchy of the tree. This sort of thing typically requires a recursive procedure:

  /* Psuedo code */
  void SaveNodesToXml(currentTreeNode, xmlDoc)
    //write info about currentTreeNode to xmlDoc...

    foreach(childNode in currentNode.Children)
      // recurse down children...
      SaveNodesToXml(childNode, xmlDoc);

Duncan Smart
Monday, December 8, 2003

How about just using the XMLSerializer to serialize the TreeView?

Robert Jacobson
Monday, December 8, 2003

*  Recent Topics

*  Fog Creek Home