Reputation: 30892
What is the best way to clear all of a asp:TreeView
checkboxes so that they are all unchecked? I've tried iterating through the treenodes and unchecking but this isn't working especially for child node checkboxes.
Upvotes: 0
Views: 1666
Reputation: 34909
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
Upvotes: 1