【问题标题】:Child nodes in excel form treeview come on same level as parentexcel表单树视图中的子节点与父节点处于同一级别
【发布时间】: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


    【解决方案1】:

    我删除了树视图,并创建了新视图。不要问我如何,但现在它可以工作了。 Microsoft Excel 的奇妙之处...

    -编辑-

    错误再次发生,因此不是孤立事件。有谁知道什么可能导致这种行为?

    【讨论】:

      猜你喜欢
      • 2012-03-25
      • 2022-09-27
      • 1970-01-01
      • 2015-03-20
      • 1970-01-01
      • 2018-06-22
      • 2017-06-07
      • 2014-04-28
      • 1970-01-01
      相关资源
      最近更新 更多