How to check if TreeView has a One Path 'LINQ'

Mansour_Dalir 2,036 Reputation points
2023-07-07T05:06:50.6466667+00:00

hi

If you have an answer with a 'linq', I would be very grateful

need If One Path

Developer technologies | VB
{count} votes

Answer accepted by question author
  1. Jiachen Li-MSFT 34,231 Reputation points Microsoft External Staff
    2023-07-07T05:39:15.08+00:00

    Hi @Mansour_Dalir ,

    You can refer to the following code.

        Private Function CheckSingleChildRootNodes(ByVal treeView As TreeView) As Boolean
    
            Return treeView.Nodes.Cast(Of TreeNode)().Any(Function(node) CheckSingleNodeAndChildren(node))
        End Function
    
        Private Function CheckSingleNodeAndChildren(ByVal node As TreeNode) As Boolean
    
            If node.Nodes.Count <> 1 Then
                Return False
            End If
    
            Dim childNode As TreeNode = node.Nodes(0)
            Return childNode.Nodes.Count = 0 OrElse CheckSingleNodeAndChildren(childNode)
        End Function
    

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.