我正在尝试检查我的树视图的根是否已经过检查。我不在乎孩子是否接受检查。
这是我的代码:
If (TreeView.Nodes.Count > 0) Then
Dim check As Boolean
check = False
Set nd = TreeView.Nodes(1).Root.FirstSibling
Do Until nd Is Nothing
If nd.Parent Is Nothing And (nd.Selected) Then
check = True
MsgBox " a root is checked !"
End If
Set nd = nd.Next
Loop
End If
If Not check Then
MsgBox "No root checked !"
End If
当没有检查任何内容时,代码可以运行。但当一个孩子检查它告诉我根检查... 我真的不知道如何改变它!
答案 0 :(得分:0)
您检查.Selected
而不是.Checked
,因此请更改为:
If nd.Parent Is Nothing And (nd.Checked) Then
或者怎么样:
Dim nd As Node, isCheckedRoot As Boolean
For Each nd In TreeView.Nodes
If nd.Parent Is Nothing And nd.Checked Then
isCheckedRoot = True
Exit For
End If
Next
MsgBox IIf(isCheckedRoot, "a root is", "No root") & " Checked"