DevExpress gets the implementation method of the collection of child nodes in the visible region under the node

  • 2020-08-22 22:39:24
  • OfStack

Retrieving nodes recursively is a common technique in many program projects. This paper shows the implementation method of DevExpress to obtain the collection of children nodes in the visible region under the node with an example. To share for your reference, the specific methods are as follows:

The key code is as follows:


/// <summary>
///  Down the recursive TreeListNode node 
/// </summary>
/// <param name="node"> Nodes that need to recurse down </param>
/// <param name="conditionHanlder"> entrust </param>
public static void DownRecursiveNode(this TreeListNode node, Action<TreeListNode> conditionHanlder)
{
  foreach (TreeListNode _childNode in node.Nodes)
  {
 conditionHanlder(_childNode);
 DownRecursiveNode(_childNode, conditionHanlder);
  }
}
/// <summary>
///  Gets a collection of child nodes in the visible region under a node 
/// </summary>
/// <param name="node"> Nodes that need to get visible children </param>
/// <param name="conditonHanlder"> Conditions to entrust </param>
/// <returns> The collection of child nodes is visible </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>
///  Gets a collection of child nodes in the visible region under a node 
/// </summary>
/// <param name="node"> Nodes that need to get visible children </param>
/// <returns> The collection of child nodes is visible </returns>
public static List<TreeListNode> GetVisibleChildNodes(this TreeListNode node)
{
  return GetVisibleChildNodes(node, n => 1 == 1);
}

Hopefully, the approach described in this article has helped you with your C# programming!


Related articles: