[英]Get checked treeview children to arraylist in c#
请有人可以帮我将树状视图的检查后的孩子获取到C#中的arraylist
You can feed the ArrayList with recursion, something like that 您可以使用递归来喂ArrayList,就像这样
// Add Node checked children into ArrayList
private static void AddCheckedNodes(TreeNode node, ArrayList list) {
if (node.Checked)
list.Add(node);
for (int i = 0; i < node.Nodes.Count; ++i)
AddCheckedNodes(node.Nodes[i], list);
}
// Add TreeView checked nodes into ArrayList
public static void AddCheckedNodes(TreeView value, ArrayList list) {
if (Object.ReferenceEquals(null, value))
throw new ArgumentNullException("value");
if (Object.ReferenceEquals(null, list))
throw new ArgumentNullException("list");
for (int i = 0; i < value.Nodes.Count; ++i)
AddCheckedNodes(value.Nodes[i], list);
}
...
AddCheckedNodes(myTreeView, myArrayList);
PS ArrayList is an obsolete class, List will be better PS ArrayList是一个过时的类,List会更好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.