附件
http://files.cnblogs.com/xe2011/ReadAndSaveTreeViewState.rar
保存和读取TreeView展开的状态 节点{ImageIndex,IsExpland,Position,Tag,Text }
//加载
private void buttonLoad_Click(object sender, EventArgs e) { treeView1.Focus(); string xmlFileName = "TreeView.xml"; if (System.IO.File.Exists(xmlFileName)) { WindowsForms.XmlTreeViewState TreeState = new WindowsForms.XmlTreeViewState(); TreeState.LoadTreeViewState(treeView1, xmlFileName); } }
写入
string xmlFileName = "TreeView.xml"; WindowsForms.XmlTreeViewState TreeState = new WindowsForms.XmlTreeViewState(); TreeState.SaveTreeViewState(treeView1, xmlFileName);
XmlTreeViewState.CS
完整的类
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
using System; using System.Xml; using System.Windows.Forms; using System.Text; //功能 //本代码是在Syed Umar Anis的 //http://www.codeproject.com/Articles/13099/Loading-and-Saving-a-TreeView-control-to-an-XML-fi //这个代码的基础上进行了修改并增加了能恢复TREEVIEW的展开的状态 和选中最后选择的一项 //1 用XML保存和读取TREE VIEW的状态 //2 将一个XML文件加载到TREEVIEW中