Question Treeview check parent node all the children

Phoenix

New member
Joined
May 12, 2011
Messages
1
Programming Experience
Beginner
hi ,

Situation is in a tree view all the nodes are prefixed by check boxes and if i do selection of parent node that once i check parent node all the children nodes at all level gets checked automatically . Please i want code for this asap with explanation also . i have been trying this from last two days .

Thanks
 
You will need to use recursion to solve this problem:

    Private Sub CallPopulateTreeView(ByVal tv As TreeView)
        PopulateEverythingUnderThisNode(tv.Nodes(0))
    End Sub
    Private Sub PopulateEverythingUnderThisNode(ByVal nd1 As TreeNode)
        For Each nd As TreeNode In nd1.Nodes
            nd.Checked = True
            PopulateEverythingUnderThisNode(nd)
        Next
    End Sub
 
I want the whole code .
I am working on visual studio 2008 and the framework is 3.5 .
Scenario is in a tree view there are parent nodes , children nodes at different level with check box . Now coding has to be done for these conditions
1. if u check any parent node then autoatically all children nodes get checked .
2 .if u check a particular child node then its parent node automatically gets checked .
Please give me the working code as soon as possible . It would be nice if you will give explantion too .
 
That is the code, my function does exactly what you asked on a treeview. It will loop through each child of a node, each child of each child, and so on and check them. You should be able to use the above code in your application which part are you having trouble with?
 
Back
Top