DevExpress获取TreeList可视区域节点集合的实现方法

本文实例展示了DevExpress获取TreeList可视区域节点集合的实现方法,是比较有实用价值的技巧。分享给大家供大家参考。具体实现方法如下:

关键代码如下:

/// <summary>
/// 获取可视区域节点
/// </summary>
/// <param name="treeList">TreeList</param>
/// <param name="conditonHanlder">条件委托</param>
/// <returns>可视区域节点集合</returns>
public static List<TreeListNode> GetVisibleNodes(this TreeList treeList, Predicate<TreeListNode> conditonHanlder)
{
  List<TreeListNode> _visibleNodes = new List<TreeListNode>();
  RowsInfo _rowsInfo = treeList.ViewInfo.RowsInfo;
  foreach (RowInfo ri in _rowsInfo.Rows)
  {
 TreeListNode _curNode = ri.Node;
 if (conditonHanlder(_curNode))
 {
   _visibleNodes.Add(_curNode);
 }
  }
  return _visibleNodes;
}
/// <summary>
/// 获取可视区域节点
/// </summary>
/// <param name="treeList">TreeList</param>
/// <returns>可视区域节点集合</returns>
public static List<TreeListNode> GetVisibleNodes(this TreeList treeList)
{
  return GetVisibleNodes(treeList, n => 1 == 1);
}

代码使用方法如下:

MessageBox.Show(tvwLamp.LHTree.GetVisibleNodes(n => n.GetNodeType() == NodeType.Cab).Count.ToString());

希望本文所述实例对大家C#程序设计能有所帮助!