tags:

views:

45

answers:

2
 Private Function Check(ByVal mytreeNode As TreeNodeCollection) As Boolean
        For Each node As TreeNode In mytreeNode
            If node.ChildNodes.Count > 0 Then
              If node.Checked = True Then
                For Each chknode As TreeNode In node.ChildNodes
                    chknode.Checked = True
                Next
            End If
          Check(node.ChildNodes)
        Next
    End Function

Using this function i can check child node when checking parent.I want to do opposite.Once i uncheck parent child also gets uncheck.It is possible using this same function.?

A: 

Do you mean to change it to using a param passed in. Something like

Private Function Check(ByVal mytreeNode As TreeNodeCollection, checked as Boolean) As Boolean 
    For Each node As TreeNode In mytreeNode 
        If node.ChildNodes.Count > 0 Then 
          If node.Checked = checked Then 
            For Each chknode As TreeNode In node.ChildNodes 
                chknode.Checked = checked 
            Next 
        End If 
      Check(node.ChildNodes, checked) 
    Next 
End Function 
astander
A: 

Add One more parameter

Private Function Check(ByVal mytreeNode As TreeNodeCollection,IsparentNodeChecked as boolean) As Boolean
        For Each node As TreeNode In mytreeNode
            If node.ChildNodes.Count > 0 Then
                For Each chknode As TreeNode In node.ChildNodes
                    chknode.Checked = IsparentNodeChecked 
                Next
            End If
          Check(node.ChildNodes,node.checked)
        Next
    End Function

try this

Vibin Jith