asp.net树形视图如何在任何级别的检查检查子节点的数量 [英] asp.net treeview how to check number of checked child nodes at any level

查看:114
本文介绍了asp.net树形视图如何在任何级别的检查检查子节点的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关于得到在任何特定层次找到在一个TreeView检查子节点的数目的要求。所检查的子节点的数目是针对每个父节点的总数进行比较。如果选中的子节点的数量小于那么这将被认为是限制,否则其全面检查该特定父总子节点。我可以通过使用parent.childnodes.count属性找到每个父子节点的总数。我没有找到得到这个数的方法。

I have a requirement regarding getting finding the number of checked child nodes in a treeview at any particular level. The number of the checked child nodes is to be compared against the total number of nodes per parent. If the number of checked child nodes is less than the total child nodes for that particular parent then this would be considered as limited otherwise its fully checked. I can find the total number of child nodes per parent by using the parent.childnodes.count property. I am failing to find a way of getting this number.

问候,

imdondo

推荐答案

递归lambda函数 FlattenTree 应该做的伎俩。

Recursive lambda function FlattenTree should do the trick.

Func<TreeNodeCollection, IEnumerable<TreeNode>> FlattenTree = null;
FlattenTree = coll => coll.Cast<TreeNode>()
                          .Concat(coll.Cast<TreeNode>()
                                      .SelectMany(x => FlattenTree(x.ChildNodes))
                           );

var nodesCount = FlattenTree(treeView.Nodes).Count();
var checkedNodesCount = FlattenTree(treeView.Nodes).Count(x=>x.Checked);

其他Linq2Object功能也是可能的。

Other Linq2Object functions are also possible

var checkedLeafNodes = FlattenTree(treeView.Nodes)
                       .Where(x => x.ChildNodes.Count == 0 && x.Checked==true)
                       .ToList();

这篇关于asp.net树形视图如何在任何级别的检查检查子节点的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆