我的代码,想做一个循环,作不料
Private Sub trvProdOne_NodeCheck(ByVal Node As MSComctlLib.Node)
Dim i As Integer
If Node.Checked = True Then
For i = 0 To Node.Children
Node.Child.Checked = True '只能一个一个往下走啊
Node.Child.Next.Checked = True
Node.Child.LastSibling.Checked = True
Next
Else
'.........
End If
End Sub
Private Sub trvProdOne_NodeCheck(ByVal Node As MSComctlLib.Node)
Dim i As Integer
If Node.Checked = True Then
For i = 0 To Node.Children
Node.Child.Checked = True '只能一个一个往下走啊
Node.Child.Next.Checked = True
Node.Child.LastSibling.Checked = True
Next
Else
'.........
End If
End Sub
Private Sub TrvMK_NodeCheck(ByVal Node As MSComctlLib.Node)
If Not Node.Parent Is Nothing Then
If Node.Parent.Checked = False Then
Node.Parent.Checked = Node.Checked
End If
End If
CheckNode Node
End Sub
Dim obj As Node
Dim I As Integer
Set obj = Node.Child
For I = 1 To Node.Children
obj.Checked = Node.Checked
CheckNode obj
Set obj = obj.Next
Next I
End Sub
'
'Author:lihonggen0
'Date:2003-1-20
'功能:选择Treeview节点下所有节点
'----------------------------------------------------------------------------Private Sub Form_Load()
TreeView1.Checkboxes = True
TreeView1.Nodes.Add , "R", "root", "root"
TreeView1.Nodes.Add "root", tvwChild, "key1", "aa"
TreeView1.Nodes.Add "key1", tvwChild, "key11", "ccc" TreeView1.Nodes.Add "root", tvwChild, "key2", "bb"
TreeView1.Nodes.Add "key2", tvwChild, "key21", "ddd"
TreeView1.Nodes.Add "key2", tvwChild, "key211", "eee"
For I = 1 To TreeView1.Nodes.Count
TreeView1.Nodes(I).Expanded = True
Next
End Sub
Private Sub CheckChild(ByVal Node As MSComctlLib.Node, ByVal bCheck As Boolean, Optional ByVal bNext As Boolean = True, Optional ByVal bChild As Boolean = True)
If Not Node Is Nothing Then
Node.Checked = bCheck
If Node.Children And bChild Then
Call CheckChild(Node.Child, bCheck, True, True) '对子节点
End If
If bNext Then
Call CheckChild(Node.Next, bCheck, True, bChild) '对同一层节点
End If
End If
End SubPrivate Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
Call CheckChild(Node, Node.Checked, False, True) '处理子节点
End Sub
去看看可能会有帮助。
http://www.csdn.com.cn
If TrView.Checkboxes = False Then Exit Sub Dim i As Integer
Dim bAll As Boolean If pNode.Checked = True Then
If pNode.Children > 0 Then
pNode.Child.FirstSibling.Checked = True
Call SelectedNode(pNode.Child.FirstSibling)
For i = 3 To pNode.Children
pNode.Child.Next.Checked = True
Call SelectedNode(pNode.Child.Next)
Next i
pNode.Child.LastSibling.Checked = True
Call SelectedNode(pNode.Child.LastSibling)
End If Else
' If Not pNode.Parent Is Nothing Then
' Call SelectedFatherNode(pNode)
If pNode.Children > 0 Then
pNode.Child.FirstSibling.Checked = False
Call SelectedNode(pNode.Child.FirstSibling)
For i = 3 To pNode.Children
pNode.Child.Next.Checked = False
Call SelectedNode(pNode.Child.Next)
Next i
pNode.Child.LastSibling.Checked = False
Call SelectedNode(pNode.Child.LastSibling)
End If
' End If
End If
'修改时更改状态
Call SelectedFatherNode(pNode)
End SubPrivate Sub SelectedFatherNode(ByVal pNode As Node)
If TrView.Checkboxes = False Then Exit Sub Dim i As Integer
Dim bAll As Boolean If pNode.Checked = True Then
'修改时更改状态
If Not pNode.Parent Is Nothing Then
Set pNode = pNode.Parent
bAll = True
bAll = bAll And pNode.Child.FirstSibling.Checked
For i = 3 To pNode.Children
bAll = bAll And pNode.Child.Next.Checked
Next i
bAll = bAll And pNode.Child.LastSibling.Checked
If bAll = True Then pNode.Checked = True
Call SelectedFatherNode(pNode)
End If
Else
If Not pNode.Parent Is Nothing Then
pNode.Parent.Checked = False
Call SelectedFatherNode(pNode.Parent)
End If
End IfEnd Sub
Dim i As Integer
Dim n As Object
Set n = Node.Child
For i = 1 To Node.Children
n.Checked = Node.Checked
Set n = n.Next
Next i
End Sub