本文介绍了选择所有树状视图项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在C#2.0中使用带复选框的TreeView控件. TreeView中有一些项目. 我的表单中有一个按钮控件. 我需要的是,当我单击按钮时,它应该选择树中存在的所有Node-checkBox(父节点和子节点).
I am Using TreeView Control in C# 2.0 with checkboxes. There are some Items in the TreeView. There is a Button Control in my form. What I need is when I click the Button it should Select all the Node-checkBoxes present in tree(Parent as well as child nodes).
推荐答案如果这是表格,例如,您可以遍历每个根节点并调用递归方法以检查该节点及其子节点.例如: 迭代: If this is forms, you can for example iterate through each root node and call a recursive method to check that node and it''s children. For example: Iteration: foreach (TreeNode node in treeView1.Nodes) { CheckItems(node); }
递归方法:
Recursive method:
private void CheckItems(TreeNode node) { node.Checked = true; foreach (TreeNode childNode in node.Nodes) { childNode.Checked = true; CheckItems(childNode); } }
更多推荐
选择所有树状视图项目
发布评论