Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
918
Tree check value
posted

I got the following code from the samples and was wondering how to make it work clear up to the root node? 

Private Sub VerifyParentNodeCheckState(ByVal descendantNode As UltraTreeNode)

' This method only has relevance for non root-level nodes

Dim parentNode As UltraTreeNode = descendantNode.Parent

If Not parentNode Is Nothing Then

' Get the nodes collection to which the specified descendantNode belongs

Dim nodesCollection As TreeNodesCollection = descendantNode.ParentNodesCollection

' Iterate the nodes collection and get a count of

' the number of checked nodes

Dim checkedNodesCount As Integer = 0

Dim i As Integer

For i = 0 To nodesCollection.Count - 1

Dim node As UltraTreeNode = nodesCollection(i)

If node.CheckedState = CheckState.Checked Then checkedNodesCount += 1

Next i

' If all the child nodes are checked, set the parent's CheckState

' to 'Checked'; if none are checked then set the parent's CheckState

' to 'Unchecked'; if some but not all are checked, make it 'Indeterminate'.

If checkedNodesCount = nodesCollection.Count Then

parentNode.CheckedState = CheckState.Checked

ElseIf checkedNodesCount <> 0 Then

parentNode.CheckedState = CheckState.Indeterminate

Else

parentNode.CheckedState = CheckState.Unchecked

End If

End If

End Sub

Parents
  • 69832
    Offline posted

    The first and second lines of code in the method are expecting descendantNode to have a parent node, which will not be the case when descendantNode is a root level node. In that case, get the TreeNodesCollection from the control's Nodes property instead of the node's Nodes property.

Reply Children