The code is as follows:
Private Sub Turn_Red (TVW As TreeView)
'MsgBox TVW. Nodes (1). FirstSibling. Index
Dim As Integer I
Dim j As Integer
Dim isRed As Boolean
For I=TVW. Nodes. The count To 1 Step - 1 'judging from the last node, it begin from the child Nodes of the lowest one layer To the superior judge
If Not TVW. Nodes (I). The Child Is Nothing Then If the node has Child Nodes'
IsRed=True 'if has been to True, the child of this node are red
For j=TVW Nodes (I). Child. FirstSibling. Index To TVW. Nodes (I). Child. LastSibling. Index
If TVW. Nodes (j)=ForeColor vbBlack Then 'If child Nodes exist color for vbBlack
IsRed=False
The Exit For
End the If
Next j
If isRed=True Then 'child nodes are all red, is the parent node as well as red
TVW. Nodes (I). ForeColor=vbRed
End the If
End the If
Next I
End Sub
CodePudding user response:
Did you write code, you want to ask??CodePudding user response:
The parent node to red first,Then a recursive loop child nodes,
Have not red, the parent node into black, and jump out of the loop,