原文链接:https://www.cnblogs.com/SoftWareIe/p/8757270.html
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;//选中一行
advTree.DragDropEnable=false; 禁止拖动 // 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 前的图片 展示
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("有三个女朋友")});//集合增加 n.image=//图片源 显示图片 n.ImageExpanded=//图片源 节点展开时显示的图片 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 } }
4.拖拽 各种限制都在BeforeNodeDrop设置 如:我只能在层级1级上相互拖动 不可去0级2级
private void AdvTree1_BeforeNodeDrop(object sender, TreeDragDropEventArgs e) { Node node = e.Node; Node pNode = e.NewParentNode; if (pNode==null) { MessageBox.Show("不能改变层级关系"); e.Cancel = true; return; } if (pNode.Level != 0) { MessageBox.Show("不能改变层级关系"); e.Cancel = true; return; } }标签:Node,控件,C#,advTree1,SelectedNode,new,Nodes,advTree,节点 From: https://www.cnblogs.com/Dongmy/p/17927850.html