Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为TreeView添加取消选中所有复选框_C#_Web Applications - Fatal编程技术网

C# 为TreeView添加取消选中所有复选框

C# 为TreeView添加取消选中所有复选框,c#,web-applications,C#,Web Applications,我有一个TreeView,每个节点都有一个复选框。我还有一个树外的复选框,当点击时需要取消选中树内的所有复选框 我如何才能做到这一点?使用递归迭代孔树状视图,并将checked属性设置为true private void Node(TreeNode root) { root.Checked = true; foreach (TreeNode childNode in root.Nodes) { childNode.Checked = true;

我有一个
TreeView
,每个节点都有一个复选框。我还有一个树外的复选框,当点击时需要取消选中树内的所有复选框


我如何才能做到这一点?

使用递归迭代孔树状视图,并将checked属性设置为true

private void Node(TreeNode root)
{
   root.Checked = true;

   foreach (TreeNode childNode in root.Nodes)
   {     
      childNode.Checked = true;

      Node(childNode);
   }
}
试一试

在面板外的复选框上添加事件处理程序

<asp:CheckBox id="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" />


感谢您的回复,但我有一个复选框,当我取消选中treeview面板外的复选框时,treeview的复选框值应该取消选中。我不确定我是否理解您的意思,但如果您想在选中和未选中状态之间切换,只需将布尔值作为参数传递并将其设置为如果需要取消选中复选框,则为false,反之亦然。
<asp:CheckBox id="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" />