Treeview - 循环所有节点并更改子节点中的文本

时间:2016-12-01 19:20:56

标签: vb.net treeview

我需要在Treeview中的所有节点上循环,然后更改它的文本如果我的字符串匹配。我发现你必须做一个递归循环,但我无法弄清楚我怎么能用它。这是递归循环:

  Private Sub PrintRecursive(ByVal n As TreeNode)
        System.Diagnostics.Debug.WriteLine(n.Text)
        MessageBox.Show(n.Text)
        Dim aNode As TreeNode
        For Each aNode In n.Nodes
            PrintRecursive(aNode)
        Next
    End Sub

    ' Call the procedure using the top nodes of the treeview.
    Private Sub CallRecursive(ByVal aTreeView As TreeView)
        Dim n As TreeNode
        For Each n In aTreeView.Nodes
            PrintRecursive(n)

        Next
    End Sub

例如,如果我的字符串是“新文件夹”,我需要在Treeview中循环使用相同的Node.text,以便我可以更改它。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

为了更改文本,您可以将旧文本和新文本作为参数提供,如下所示:

[zzhao010@localhost shareLibPlay]$ ./3.out
i am ok

这样,每个节点都会检查文本,如果现有文本与您要查找的文本匹配,则会应用新文本。

相关问题