[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());

希望有所帮助!

你可能感兴趣的:(DevExpress)