循环第一个根节点(Nodes[0])下的子节点(Node)并添加子节点 foreach (Node tn in clTree1.advTree1.Nodes[0].Nodes) { Node n = new Node(); n.Text = "a"; n.Cells.Add(new DevComponents.AdvTree.Cell("b") n.Cells.Add(new DevComponents.AdvTree.Cell("c"); tn.Nodes.Add(n); } 隐藏节点第3列的数据 clTree1.advTree1.Columns[3].Visible = false; private void AdvTree1_NodeClick(object sender, DevComponents.AdvTree.TreeNodeMouseEventArgs e) { //是否选中的是父节点还是子节点(选中父节点会报错) if (e.Node.Nodes.Count != 0 || e.Node.Parent == null) { return; } //获取选中节点的全部内容 string n = clTree1.advTree1.SelectedNode.ToString(); //获取选中节点索引wei0的内容 string falg_str = e.Node.Cells[0].Text.ToString().Trim(); }
0.属性和方法
//属性方法 advTree1.DragDropEnabled = !advTree1.DragDropEnabled;//控制是否可以拖动节点到 不同的层级下 advTree1.MultiSelect = !advTree1.MultiSelect;//控制节点是否可以多选 advTree1.ExpandButtonType = DevComponents.AdvTree.eExpandButtonType.Triangle;//展开节点前边的图标 三角形 advTree1.ExpandButtonType = DevComponents.AdvTree.eExpandButtonType.Ellipse;//圆形中间一个线 advTree1.ExpandButtonType = DevComponents.AdvTree.eExpandButtonType.Image;//展开下边1的图 折叠下边0的图 advTree1.ExpandImage = imageList1.Images[1]; advTree1.ExpandImageCollapse = imageList1.Images[0]; advTree1.ExpandButtonType = DevComponents.AdvTree.eExpandButtonType.Rectangle;//默认方块形中间加一个线 advTree1.ExpandButtonSize = new Size(10, 10);//展开按钮大小 默认8,8 advTree1.SelectionBoxStyle = DevComponents.AdvTree.eSelectionStyle.FullRowSelect;//选中一行 // advTree1.Nodes.Clear();//清空所有节点 advTree1.ExpandAll();//全部展开 advTree1.CollapseAll();//全部折叠 Node n = advTree1.SelectedNode.Copy();//复制先中节点 advTree1.SelectedNode.Remove();//移除节点 advTree1.Nodes.Add(n);//添加节点
1.对advTree操作都是在Nodes属性基础上的如:新建 一个Node并添加到tree中
Node n = new Node();//节点下再加节点 像部门档案等可递归实现 n.Text = "小张"; n.Nodes.Add(new Node("男")); n.Nodes.Add(new Node("18")); n.Nodes.Add(new Node("小张永远18,你懂得")); n.Nodes.AddRange(new Node[] { new Node("汉"), new Node("有三个女朋友")});//集合增加 advTree1.Nodes.Add(n);
2.取选中节点的值
advTree1.SelectedNode.Text;
3.选中时节点 执行操作(SelectedIndexChanged)
private void AdvTree1_SelectedIndexChanged(object sender, EventArgs e) { //MessageBox.Show(advTree1.SelectedNode.Text); //层级 if (advTree1.SelectedNode.Level == 0) { //语句1 } else if (advTree1.SelectedNode.Level ==1) { //语句2 } }