tags:

views:

36

answers:

1

Hi Everybody,

I want to be able to view a XML file in treeview, and the user can drag the node around in treeview, or delete some node, then the change should be automatically reflected in the XML file. To give an example of my purpose, think of the Favorites hierachy in IE:

The XML file before modification:

<Folder FolderName="Favorites">
    <Folder FolderName="Google Websites" >
        <Favorite url="www.google.com">Google</Favorite>
    </Folder>
</Folder>

The treeview before modification:

-Favorites    
--Google Websites  
---Google  

The user dragged a node in the treeview, the treeview becomes:

-Favorites
--Google
--Google Websites

Then the XML file should be automatically modified to reflect the change in the treeview:

<Folder FolderName="Favorites">
    <Favorite url="www.google.com">Google</Favorite>
    <Folder FolderName="Google Websites" >
    </Folder>
</Folder>

Right now I am able to display the XML in treeview, can drag node around in treeview, but I don't know how to make the XML reflect the changes in the treeview. Anyone can give me some hint about how to do this in C#? Thanks in Advance.

Vincent

A: 

You didn't specify the presentation technology that you are trying to employ.

However, if you are using WPF or Silverlight, the answer is covered in depth in the following question: Two-way binding of Xml data to the WPF TreeView.

Since you're using Windows Forms, I would suggest taking a look at my CodeProject article about ForestPad.

Timothy Lee Russell
Thanks Timonthy, I was using Windows Form. I am not very familiar with WPF, but I will see whether I can get some idea from the link that you gave. Thanks!
Vincent
@Vincent, check my edit -- the CodeProject article has sample code for doing this in Windows Forms.
Timothy Lee Russell
Thanks Timothy. I somehow managed to do that using XmlDocument. Your project is a little too complicated for my purpose, but thank you for answering my question!Vincent
Vincent