You cannot have radio buttons in a TreeView, only checkboxes.
A solution would be to make the checkboxes behave like radio buttons:
Private Sub TreeView1_AfterCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterCheck
If e.Node.Checked Then
If e.Node.Level = 2 Then
For Each node As TreeNode In e.Node.Parent.Nodes
If node IsNot e.Node Then
node.Checked = False
End If
Next
Else
e.Node.Checked = False
End If
End If
End Sub
The e.Node.Level = 2
check makes sure only grandchild nodes behave like radio buttons.
Set the TreeView's CheckBoxes
property to True
to enable checkboxes.
This is an example of how to change text style of selected nodes and its parents:
Private Sub TreeView1_BeforeSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles TreeView1.BeforeSelect
If TreeView1.SelectedNode IsNot Nothing Then
MakeSelected(TreeView1.SelectedNode, False)
End If
MakeSelected(e.Node, True)
End Sub
Private Sub MakeSelected(ByVal node As TreeNode, ByVal selected As Boolean)
Dim SelectedFont As New Font(TreeView1.Font, FontStyle.Bold)
node.NodeFont = IIf(selected, SelectedFont, TreeView1.Font)
node.ForeColor = IIf(selected, Color.Blue, TreeView1.ForeColor)
If node.Parent IsNot Nothing Then
MakeSelected(node.Parent, selected)
End If
End Sub
It recursively changes the text style of the selected node and its parents and sets it back to the TreeView's default style when the selection changes.