简体   繁体   English

清除所有asp:TreeView复选框

[英]Clear all asp:TreeView checkboxes

What is the best way to clear all of a asp:TreeView checkboxes so that they are all unchecked? 清除所有asp:TreeView复选框以便不选中它们的最佳方法是什么? I've tried iterating through the treenodes and unchecking but this isn't working especially for child node checkboxes. 我尝试遍历treenodes并取消选中,但这不适用于子节点复选框。

Your own answer is close, but won't traverse down the tree. 您自己的答案很接近,但是不会遍历树。 Try a recursive method like this. 尝试这样的递归方法。

   Private Sub unCheckNodesIncludingDescendants(Node as TreeNode)
        Node.checked=false
        For Each tn As TreeNode In Node.ChildNodes
            tn.Checked = False
            unCheckNodesIncludingDescendants(tn)
        Next tn
    End Sub

Your initial call would look like this: 您的初始通话将如下所示:

private sub UncheckWholeTree(TreeControl as TreeView)
    For each rootNode as TreeNode in TreeControl.nodes
      unCheckNodesIncludingDescendants(rootNode)
    Next rootNode
end sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM