第三方的增强型树型控件Aga.Controls是勇哥常用的控件。
由于其使用方法常用常忘,这里记录一下以备察。
Aga.Controls的扩展能力如下:
自带勾选与图标,图标是可以更换的。
子节点可以拖放换位置,子节点可以拖放成根结点
根点与子结点都可以更名
常见的需求主要是要判定节点是根还是子节点,同一级节点有多少等等。
演示代码,读树节点全部的信息:
/// <summary> /// 读调试树的信息 /// </summary> /// <param name="tree"></param> /// <returns></returns> public List<DebugNodeStruct> ReadTreeInfo(TreeViewAdv tree) { List<DebugNodeStruct> data = new List<DebugNodeStruct>(); foreach (var m in tree.AllNodes) { int nodetype = 0; Node node = m.Tag as Node; var data1 = node.Text.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); if (data1.Length < 2) { if (node.Parent.Index == -1) nodetype = 6; } else { try { var selobj = new enumHelper<DebugTreeActionNameEnum>().stringToEnum(data1[0]); switch (selobj) { case DebugTreeActionNameEnum.输出IO: nodetype = 1; break; case DebugTreeActionNameEnum.输入IO: nodetype = 2; break; case DebugTreeActionNameEnum.气缸: nodetype = 3; break; case DebugTreeActionNameEnum.轴: nodetype = 4; break; case DebugTreeActionNameEnum.动作: nodetype = 5; break; } } catch { return data; } } data.Add(new DebugNodeStruct() { NodeName = node.Text, ParentNodeName = node.Parent == null ? "" : node.Parent.Text, NodeLevel = m.Level, Index = node.Index, CheckStatus = (int)node.CheckState, NodeType = nodetype }); } return data; }
public struct DebugNodeStruct { /// <summary> /// 节点名字 /// </summary> public string NodeName; /// <summary> /// 节点级别,顶层节点为0 /// </summary> public int NodeLevel; /// <summary> /// 父结点的名字 /// </summary> public string ParentNodeName; /// <summary> /// 同父节点的子项目的索引号 /// </summary> public int Index; /// <summary> /// 选择的状态,有三种: 0不勾选Unchecked, 1勾选Checked, 2不确定Indeterminate(暂时不支持此状态,为保留状态) /// </summary> public int CheckStatus; /// <summary> /// 结点类型 /// </summary> public int NodeType; }
另一个常见问题:
TreeViewAdv控件为啥添加根节点看不到内容
控件源代码及演示程序下载:
为了避免网络机器人采集下载,不得已,资源需要扫码付费下载。
你也可以自己去csdn上去下载。
---------------------
作者:hackpig
来源:www.skcircle.com
版权声明:本文为博主原创文章,转载请附上博文链接!
本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:


