Recursively obtaining nodes is a common trick in many program projects. This article uses an example to show the implementation method of obtaining the visual area child node set under the node. I will share it with you for reference. The specific methods are as follows:
The key part of the code is as follows:
/// <summary> /// Down recursive TreeListNode node/// </summary> /// <param name="node">Node that requires downward recursion</param>/// <param name="conditionHanlder">Trust</param>public static void DownRecursiveNode(this TreeListNode node, Action<TreeListNode> conditionHanlder) { foreach (TreeListNode _childNode in ) { conditionHanlder(_childNode); DownRecursiveNode(_childNode, conditionHanlder); } } /// <summary> /// Get the collection of child nodes with visual area under node/// </summary> /// <param name="node">Node that needs to obtain visible child nodes</param>/// <param name="conditonHanlder">Conditional delegation</param>/// <returns>Visible child node collection</returns>public static List<TreeListNode> GetVisibleChildNodes(this TreeListNode node, Predicate<TreeListNode> conditonHanlder) { List<TreeListNode> _visibleChildNodes = new List<TreeListNode>(); TreeList _tree = ; DownRecursiveNode(node, n => { RowInfo _rowInfo = _tree.[n]; if (_rowInfo != null) { if (conditonHanlder(n)) { _visibleChildNodes.Add(n); } } }); return _visibleChildNodes; } /// <summary> /// Get the collection of child nodes with visual area under node/// </summary> /// <param name="node">Node that needs to obtain visible child nodes</param>/// <returns>Visible child node collection</returns>public static List<TreeListNode> GetVisibleChildNodes(this TreeListNode node) { return GetVisibleChildNodes(node, n => 1 == 1); }
I hope the methods described in this article will be helpful to everyone's C# programming!