VB.NET 如何将子节点添加到树视图中的特定节点 [英] VB.NET How to add a child node to a specific node in treeview

查看:47
本文介绍了VB.NET 如何将子节点添加到树视图中的特定节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将子节点添加到树视图中的特定节点?假设我已经在树视图中有Item1",如何将SubItem1"添加到Item1"作为它的子节点?

How to add a child node to a specific node in treeview? Say I have "Item1" in treeview already, how do I add "SubItem1" to "Item1" as it's child node?

我知道它可能真的很简单,但我尝试了很多东西,我就是无法让它工作.

I know its probably really simple, but i tried lots of stuff, i just cant get it working.

推荐答案

将子节点添加到父节点(未选中)

首先使用 Find() 获取对父节点的引用.然后使用与下面其他部分相同的技术添加它.

Adding child node to parent (non-selected)

First use Find() to get a reference to the parent node. Then add it using the same technique as the other sections below.

Dim MyNode() As TreeNode 
MyNode = TreeView1.Nodes.Find("Item1", True)
MyNode(0).Nodes.Add("SubItem1")

以编程方式添加节点

如果要将子节点添加到特定的父节点,想法是使用parent.node.add() 方法将子节点添加到其父节点.您可以像这样创建任意数量的子项.

Adding nodes programmatically

If you want to add the child nodes to a particluar parent node, the idea is to add the child nodes to their parent node by using the parent.node.add() method. You can create any number of child like this.

例如,如果您想要一个类似的场景:

祖父->父亲->儿子

然后你可以这样做:

dim GrandfatherNOde as treenode = tree.nodes.add("Grandfather")
dim fatherNode as treenode = GrandfatherNode.Nodes.add("Father")
dim sonNode as treenode = fatherNode.Nodes.add("Son")

更多阅读/例子

这个页面有一个很好的例子,你可以运行它来动态地将子节点添加到树中.他们通过一个按钮来完成,他们像这样连接:

More reading/examples

This page has a good example you can run to dynamically add child nodes to the tree. They do it on a button, which they've hooked up like this:

Private Sub AddChild_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddChild.Click
    TView.SelectedNode.Nodes.Add(Text1.Text)
End Sub

http://www.codeproject.com/Articles/11830/The-Basic-Operations-on-using-the-TreeView-Control

这篇关于VB.NET 如何将子节点添加到树视图中的特定节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆