遞歸獲取節點是很多程序項目中常見的技巧。本文就以實例展示了DevExpress獲取節點下可視區域子節點集合的實現方法。分享給大家供參考之用,具體方法如下:
關鍵部分代碼如下:
/// <summary>/// 向下遞歸TreeListNode節點/// </summary>/// <param name="node">需要向下遞歸的節點</param>/// <param name="conditionHanlder">委托</param>public static void DownRecursiveNode(this TreeListNode node, Action<TreeListNode> conditionHanlder){ foreach (TreeListNode _childNode in node.Nodes) { conditionHanlder(_childNode); DownRecursiveNode(_childNode, conditionHanlder); }}/// <summary>/// 獲取節點下可視區域子節點集合/// </summary>/// <param name="node">需要獲取可見子節點的節點</param>/// <param name="conditonHanlder">條件委托</param>/// <returns>可見子節點集合</returns>public static List<TreeListNode> GetVisibleChildNodes(this TreeListNode node, Predicate<TreeListNode> conditonHanlder){ List<TreeListNode> _visibleChildNodes = new List<TreeListNode>(); TreeList _tree = node.TreeList; DownRecursiveNode(node, n => { RowInfo _rowInfo = _tree.ViewInfo.RowsInfo[n]; if (_rowInfo != null) { if (conditonHanlder(n)) { _visibleChildNodes.Add(n); } } }); return _visibleChildNodes;}/// <summary>/// 獲取節點下可視區域子節點集合/// </summary>/// <param name="node">需要獲取可見子節點的節點</param>/// <returns>可見子節點集合</returns>public static List<TreeListNode> GetVisibleChildNodes(this TreeListNode node){ return GetVisibleChildNodes(node, n => 1 == 1);}
希望本文所述方法對大家的C#程序設計能有所幫助!
新聞熱點
疑難解答