|
|
Title | Select a TreeView subtree when the user selects a node in VB .NET |
Description | |
Keywords | VB.NET, TreeView, subtree, select |
Categories | Controls, VB.NET |
|
|
In the TreeView's AfterCheck event handler, see if the clicked node is checked or unchecked and call subroutine SetSubtreeChecked. SetSubtreeChecked sets a node's Checked value and then recursively calls itself to set the Checked value for that node's descendants.
|
|
' Check or uncheck all nodes in this node's subtree.
Private Sub trvMeals_AfterCheck(ByVal sender As Object, _
ByVal e As System.Windows.Forms.TreeViewEventArgs) _
Handles trvMeals.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
|
|
|
|
|
|