I have a 3 layer treeview and is using the code below. I am getting it to do the following,
1) If parent is checked, check all child nodes.
2) If just one child node is unchecked, uncheck parent node.
3) If all child nodes are checked, check parent node.
Code below only works for 2 layers. Would appreciate if you can guide me how to make it three. There are much information on treeview but most of them seems irrelevant =/ Will be great if you can show me a good guide on treeview control. Thank you!
Private Sub TreeView1_AfterCheck(ByVal sender As Object, ByVal e As TreeViewEventArgs) Handles TreeView1.AfterCheck
RemoveHandler TreeView1.AfterCheck, AddressOf TreeView1_AfterCheck
For Each node As TreeNode In e.Node.Nodes
node.Checked = e.Node.Checked
Next
If e.Node.Checked Then
If e.Node.Parent Is Nothing = False Then
Dim allChecked As Boolean = True
For Each node As TreeNode In e.Node.Parent.Nodes
If Not node.Checked Then
allChecked = False
End If
Next
If allChecked Then
e.Node.Parent.Checked = True
End If
End If
Else
If e.Node.Parent Is Nothing = False Then
e.Node.Parent.Checked = False
End If
End If
AddHandler TreeView1.AfterCheck, AddressOf TreeView1_AfterCheck
End Sub