private void LoadTree() { TreeNodeItem root = new TreeNodeItem(); root.ImageIndex = 0; root.Text = "Tree"; string[] parents = { "C#", "JAVA", "PYTHON", "C++", "C", "JAVASCRIPT" }; string[] infos = { "01", "02", "03", "04", "05", "06" }; List <TreeNodeItem> treeNodes = new List <TreeNodeItem>(); foreach (var item in parents) { TreeNodeItem treeNodeItem = new TreeNodeItem(); treeNodeItem.Text = item; treeNodeItem.ImageIndex = 0; foreach (var ch in infos) { treeNodeItem.Nodes.Add(new TreeNodeItem() { Text = ch, ImageIndex = 1 }); } treeNodes.Add(treeNodeItem); } root.Open = true; root.Nodes.AddRange(treeNodes); treeView1.Nodes.Add(root); }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { TreeNodeItem ti = e.Node as TreeNodeItem; if (ti != null) { textBox1.Text = ti.node.ToFullString(); } }
protected virtual void OnDrawNode(Graphics g, SolidBrush brush, Pen pen, TreeNodeItem node) { if (SelectedNode == node) { using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(75, 110, 175))) g.FillRectangle(solidBrush, node.Bounds); //brush.Color = Color.White; pen.Color = Color.White; } else { //brush.Color = this.ForeColor; pen.Color = this.ForeColor; } if (node.ForeColor != Color.Transparent) { brush.Color = node.ForeColor; } else { brush.Color = this.ForeColor; } int x = node.Level * indent + 7; g.DrawLine(pen, x + 8, node.Bounds.Y + rowHeight / 2, x + 23, node.Bounds.Y + rowHeight / 2); if (node.Nodes.Count > 0)//开关 { if (node.Open) { g.DrawLine(pen, x + 31, node.Bounds.Y + rowHeight - 13, x + 31, node.Bounds.Y + GetChildCount(node) * rowHeight + rowHeight / 2);//纵线 g.DrawImage(ImageCloseIcon, node.SwitchBounds); } else { g.DrawImage(ImageOpenIcon, node.SwitchBounds); } } //文件夹 if (ImageList != null) { Image image = ImageList.Images[node.ImageIndex]; g.DrawImage(image, x + 25, node.Bounds.Y + 3); } //if (!node.Folder) // g.DrawImage(FileIcon, x + 25, node.Bounds.Y + 3); //else // g.DrawImage(FolderIcon, x + 25, node.Bounds.Y + 3); g.DrawString(node.Text, this.Font, brush, x + 50, node.Bounds.Y + 3); }
/// <summary> /// 获取node节点下所有已展开的字节点 /// </summary> /// <param name="node"></param> /// <returns></returns> public int GetChildCount(TreeNodeItem node) { int count = node.Nodes.Count; foreach (var item in node.Nodes) { if (item.Open) { count += GetChildCount(item); } } return(count); }
private void DrawNode(Graphics g, SolidBrush brush, Pen pen, TreeNodeItem node) { node.SwitchBounds = new Rectangle(node.Level * indent + 7, node.Bounds.Y + 6, 12, 12); OnDrawNode(g, brush, pen, node); VirtualHeight += node.Bounds.Height; if (node.Open) { foreach (var item in node.Nodes) { draw_y += rowHeight; item.Bounds = new Rectangle(0, draw_y, this.Width, rowHeight); item.Level = node.Level + 1; DrawNode(g, brush, pen, item); } } }
void PrintTree(SyntaxNode sn, TreeNode parentNode) { //for (int i = 0; i < depth; i++) // Console.Write("\t"); //Console.WriteLine("{0}", node.GetType().ToString()); TreeNodeItem treeNodeItem = new TreeNodeItem(sn); parentNode.Nodes.Add(treeNodeItem); if (sn.ChildNodes().Count() > 0) { foreach (var c in sn.ChildNodes()) { //PrintTree(c, ++depth); PrintTree(c, treeNodeItem); } } }
private IEnumerable <Object> CreateTreeOrderedList(TreeNodeItem parent, ILookup <Object, TreeNodeItem> treeLp) { if (parent == null || parent.DataItem == null) { yield break; } yield return(parent.DataItem); var children = treeLp[parent.PrimaryKey]; foreach (var child in children) { foreach (var subChild in CreateTreeOrderedList(child, treeLp)) { yield return(subChild); } } }
public void SetCachedNodes(TreeNodeItem rootNode) { }