【发布时间】:2016-06-07 17:30:48
【问题描述】:
我希望有人可以帮助我,因为我已经坚持了好几天了。
我有一个要在树视图中可视化的工作表。 因为这是我的第一个问题,而且我的声誉不够高,所以在链接中提供了图像。 img of Worksheet to visualise
'i:loop through objects
'j:loop through object childs
'counter: keep track of how many childs processed
For i = 1 To 5
Set parentCell = rng.Offset(counter, 0) 'parent values
strParent = parentCell.Value 'parent values
' Build the treeview for both the Left and the right side of the screen
trvLeft.Nodes.Add Key:=strParent, Text:=strParent
trvRight.Nodes.Add Key:=strParent, Text:=strParent
For j = 1 To HelperMethods.AmountInEntity 'can be any number
strPresent = rng.Offset(counter, 6).Value '"x" or ""
'Add to left treeview
Call trvLeft.Nodes.Add(Relative:=strParent, Relationship:=tvwChild, Key:=rng.Offset(counter, 4).Value, Text:=rng.Offset(counter, 4).Value)
'add to right treeview. If not present, mark as red.
If strPresent = "x" The
Call trvRight.Nodes.Add(Relative:=strParent, Relationship:=tvwChild, Key:=rng.Offset(counter, 5).Value, Text:=rng.Offset(counter, 5).Value)
Else
With trvRight.Nodes.Add(strParent, tvwChild, rng.Offset(counter, 5).Value, rng.Offset(counter, 5).Value)
.ForeColor = vbRed
End With
End If
counter = counter + 1
Next j
Next i
将节点添加到其父节点时出现问题,因为所有节点都是在同一级别上创建的。
我注意到一件奇怪的事情,父母被添加到列表的底部,而孩子被添加到列表的顶部。 img of flat tree
提前致谢,
菲利普
【问题讨论】:
标签: excel forms treeview nodes