这里我有下面的 TreeView ,如图所示。
对于子节点G g
我想从下到上获取所有父节点名称并存储到列表中。表示列表中应添加 G g、F f、D d、B b。
请提出解决方案。
提前致谢...
最佳答案
我为它创建了一个函数,它将添加列表中的所有父节点,直到父节点对于所选节点来说不是空的。
Public Function AllParents() As List(of String)
Dim listOfNodeHierarchy As New List(Of String)
listOfNodeHierarchy.Add(node.ToString)
'If Child Node has parent, add the parent name of the Child node to the list
While (node.Parent IsNot Nothing)
listOfNodeHierarchy.Add(node.Parent)
node = node.Parent
End While
return listOfNodeHierarchy
End Function
关于vb.net - 如何使用vb.net在 TreeView 控件中从下到上查找子节点的所有父节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27017057/