简体   繁体   中英

How to databind a XML file with a treeview in C#

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM