Hello,

I'm building an application and using a Treeview to be able to select multiple items and subtree items. I'm currently using the following code snippet:

Private Sub tvCompanyList_AfterCheck(ByVal sender As Object, _
ByVal e As System.Windows.Forms.TreeViewEventArgs) _
Handles tvCompanyList.AfterCheck
Dim parent_node As TreeNode = e.Node
Dim is_checked As Boolean = parent_node.Checked
For i As Integer = 0 To e.Node.Nodes.Count - 1
SetSubtreeChecked(parent_node.Nodes(i), is_checked)
Next i
End Sub

' Set the Checked property for all nodes in the subtree.
Private Sub SetSubtreeChecked(ByVal parent_node As _
TreeNode, ByVal is_checked As Boolean)

' Set the parent's Checked value.
parent_node.Checked = is_checked

' Set the child nodes' Checked values.
For i As Integer = 0 To parent_node.Nodes.Count - 1
SetSubtreeChecked(parent_node.Nodes(i), is_checked)
Next i
End Sub

Currently selecting the Parent Node selects everything in the subtree which is something I want, but I want some other functionality.

-Deselecting all items in a subtree, deselects the parents.
-Deselecting an item in a subtree changes the checkmark in the parent check box to a square.
-Checked box next to any item highlights it.

I'm fairly new to VB and I'm trying to learn as a hobby. Any pointers on this?