我正在尝试根据表单加载中存储在数据库中的内容将节点添加到树视图中。我正在使用2个级别的节点;一个根和一个级别的孩子。当我遍历树视图中当前存储的内容时,程序拒绝返回NULL响应,以便满足条件。
我的代码
Sub PopulateTree()
Dim RNum As Integer = RecNum()
Dim TreeData() As Tree = GetTreeValues(RNum)
Dim I = 0
Dim allnodes As TreeNodeCollection = treHierarchy.Nodes
For I = 0 To RNum - 1
'find the notation of reading the properties of a node
MsgBox(treHierarchy.Nodes(I).Name.ToString)
MsgBox(TreeData(I).Parent)
'If the node is equal to the parent of THAT record, then append the child
If treHierarchy.Nodes(I).Name = TreeData(I).Parent Then
treHierarchy.SelectedNode = treHierarchy.Nodes(I)
treHierarchy.SelectedNode.Nodes.Add(TreeData(I).Child)
'If the node is equal to A parent BUT NOT the parent of THAT record, then skip.
'When the code hits the end, create the new parent
ElseIf treHierarchy.Nodes(I).Text <> TreeData(I).Parent Then
For Each TreeNode In allnodes
If TreeNode <> TreeData(I).Parent Then
treHierarchy.Nodes.Add(TreeData(I).Parent)
treHierarchy.SelectedNode = treHierarchy.Nodes(I)
treHierarchy.SelectedNode.Nodes.Add(TreeData(I).Child)
Else
treHierarchy.SelectedNode = treHierarchy.Nodes(I)
treHierarchy.SelectedNode.Nodes.Add(TreeData(I).Child)
End If
Next
'If the node is a child, then skip
End If
Next
End Sub
我试图用评论来解释(部分对自己),我想对IF语句的每个部分做些什么