void node_LoadData(object sender, EventArgs e) { FileNode node = (FileNode)sender; if (node != null) { TemplateFile f = (TemplateFile)node.Tag; IList<TemplateFile> list=f.Files; if (list != null && list.Count > 0) { foreach (var m in list) { FileNode t = new FileNode(m.Name); t.LoadData += new EventHandler(node_LoadData); t.Tag = m; t.SelectedImageIndex = t.ImageIndex = 0; if (m.Type == FileType.File) { t.Nodes.Clear(); t.SelectedImageIndex = t.ImageIndex = 1; EventHandler handler=new EventHandler(openfile); t.ContextMenu = new ContextMenu(new MenuItem[]{ new MenuItem("查看",handler) }); } node.Nodes.Add(t); } } } }
private void CodeTemplate_Load(object sender, EventArgs e) { TemplateFile root = TemplateManager.GetInstance("Template"); FileNode node = new FileNode(root.Name); node.Tag = root; node.SelectedImageIndex = node.ImageIndex = 0; node.LoadData += new EventHandler(node_LoadData); this.treeView1.BeforeExpand += new TreeViewCancelEventHandler(treeView1_BeforeExpand); this.treeView1.Nodes.Add(node); }