介于树节点的展开与收缩是经常多处使用的,这里就写个两个调用方法。
/// <summary> /// 展开指定节点以及其父节点 /// </summary> /// <param name="tree">树</param> /// <param name="appointNode">要展开的节点</param> public static void ExpandAppointTreeNode(this TreeList tree, TreeListNode appointNode) { tree.Nodes.TreeList.FindNodeByID(appointNode.Id).Expanded = true; while (appointNode.ParentNode != null) { tree.Nodes.TreeList.FindNodeByID(appointNode.ParentNode.Id).Expanded = true; appointNode = appointNode.ParentNode; } } /// <summary> /// 收缩指定节点 /// </summary> /// <param name="tree">树</param> /// <param name="appointNode">要收缩的节点</param> public static void ShrinkAppointTreeNode(this TreeList tree, TreeListNode appointNode) { tree.Nodes.TreeList.FindNodeByID(appointNode.Id).Expanded = false; }View Code