Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'ノード3 Dim target As TreeNode = TreeView1.Nodes(0).Nodes(0).Nodes(0).Nodes(0) '親を辿ってルートを得る Dim root1 As TreeNode = 再帰(target) '再帰では× Dim root2 As TreeNode = ループ(target) 'ループでは〇 End Sub Private Function 再帰(node As TreeNode) As TreeNode If node Is Nothing Then Return Nothing Dim temp As TreeNode = node If temp.Level > 0 Then 再帰(temp.Parent) End If Return temp End Function Private Function ループ(node As TreeNode) As TreeNode If node Is Nothing Then Return Nothing Dim temp As TreeNode = node While temp.Level > 0 temp = temp.Parent End While Return temp End Function