' Purpose: ' Author:吴文智 ' Date:2001-11-07 'Description:要试用本例请在窗体中填加一个TreeView ' 然后在代码窗体中粘贴如下代码 ' Good luck!Option ExplicitPrivate Sub Form_Load() With Me.TreeView1 '必须让树有复选框才能多选,变通风格时只能选定一项 .Checkboxes = True .Nodes.Add , , "N1", "节点1" .Nodes.Add "N1", tvwChild, "N2", "节点2" .Nodes.Add "N2", tvwChild, "N3", "子节点1" .Nodes.Add "N2", tvwChild, "N4", "子节点2" End With End Sub Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node) Dim nodEach As Node
'有子节点就选中它们 If Node.Children > 0 Then For Each nodEach In TreeView1.Nodes If nodEach.Parent Is Nothing Then '这是根节点 Else If nodEach.Parent.Key = Node.Key Then '是所选节点的子节点 nodEach.Checked = True End If End If Next End If End Sub
' Author:吴文智
' Date:2001-11-07
'Description:要试用本例请在窗体中填加一个TreeView
' 然后在代码窗体中粘贴如下代码
' Good luck!Option ExplicitPrivate Sub Form_Load()
With Me.TreeView1
'必须让树有复选框才能多选,变通风格时只能选定一项
.Checkboxes = True
.Nodes.Add , , "N1", "节点1"
.Nodes.Add "N1", tvwChild, "N2", "节点2"
.Nodes.Add "N2", tvwChild, "N3", "子节点1"
.Nodes.Add "N2", tvwChild, "N4", "子节点2"
End With
End Sub
Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
Dim nodEach As Node
'有子节点就选中它们
If Node.Children > 0 Then
For Each nodEach In TreeView1.Nodes
If nodEach.Parent Is Nothing Then
'这是根节点
Else
If nodEach.Parent.Key = Node.Key Then
'是所选节点的子节点
nodEach.Checked = True
End If
End If
Next
End If
End Sub