vb.net - 如何使用vb.net在 TreeView 控件中从下到上查找子节点的所有父节点

标签 vb.net treeview

这里我有下面的 TreeView ,如图所示。

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/

相关文章:

javascript - 从 StringBuilder(vb.net) 调用函数

wpf - 为什么 ScrollViewer 中鼠标滚轮滚动消失了?

html - 可扩展的树形菜单列表

sql-server - 如何通过VB.NET在sql server数据库中存储和检索图像

.net - 如何在没有窗口句柄的情况下使用 RegisterDeviceNotification?

wpf - TreeView 同步到 View 模型中的 SelectedItem

winforms - 在 PowerShell 中过滤 TreeView 节点

c# - 复杂的Silverlight TreeView,嵌套层次结构可能吗?

asp.net - 无法在 OpenXMl Cell 样式中使用多种字体

.net - 为什么我不能这样做 - 创建一个 .net 对象并在一行上调用一个方法