private void InstructorTree_Load(object sender, EventArgs e)
{
xmlfile = Application.StartupPath + "\\CC08Help.xml";
GetInsEvent += new GetInstructorHandle(HelpForm_GetInsEvent);
GetHtmlEvent += new GetNodeHtml(InstructorTree_GetHtmlEvent);
ReadXMLGetFileName();
this.tvHelp.ImageList = this.imgLHelp;
//由Excel导出的XML文档动态生成树
if (xmlfile != "")
{
InitTreeView(xmlfile, this.tvHelp);
}
foreach (TreeNode tn in tvHelp.Nodes)
{
SetLeafNodeImageIndex(tn);
}
this.tvHelp.Nodes[0].Expand();
}
private TreeNode curTn = null;
private void InitTreeView(string xmlfileName, TreeView tv)
{
XmlDocument xdoc = new XmlDocument();
xdoc.Load(xmlfileName);
XmlNode xn = xdoc.SelectSingleNode("Help");
TreeNode tn = new TreeNode();
tn.Text = xn.ChildNodes[0].Attributes[0].Value;//命令联机帮助
tv.Nodes.Add(tn);
makeOutTreeView(xn.ChildNodes[0], tn); //递归
}
private void makeOutTreeView(XmlNode xn,TreeNode tn)
{
if (xn.ChildNodes.Count != 0)
{
for (int i = 0; i < xn.ChildNodes.Count; i++)
{
curTn = new TreeNode();
curTn.Text = xn.ChildNodes[i].Attributes[0].Value;
tn.Nodes.Add(curTn);
makeOutTreeView(xn.ChildNodes[i], curTn);
}
}
}
posted on 2009-02-20 15:21
天书 阅读(1110)
评论(0) 编辑 收藏 引用