将 TReeView 节点移动到根节点(包含全部)Vb.net
我已经填充了一个treeView(在vb.net中),并且想将所有节点或所有树移动到包含所有内容的根节点
我有这个:
Root1
---Water
---Dirt
-----Fire
-----Stone
---UFOs
Root2
---Acid
-----H20
-----TNT
并将所有内容放入一个“Megaroot”
MEgaRoot
---Root1
------Water
------Dirt
--------Fire
--------Stone
------UFOs
---Root2
------Acid
--------H20
--------TNT
也许它这很容易,但这是我不知道如何解决这个问题的日子之一。
谢谢大家的回复
问题已解决:
Dim Counter As Integer = trvItems.Nodes.Count
Dim oldRoot As TreeNode
Dim newRoot = New TreeNode("Megaroot")
For i As Integer = 0 To Counter - 1
oldRoot = trvItems.Nodes(0)
trvItems.Nodes.Remove(oldRoot)
newRoot.Nodes.Add(oldRoot)
Next i
newRoot.Expand()
I Have a treeView Already populated (in vb.net) and would Like to move all the nodes or all the Tree for this matter, to a Root node that Contains it all
I Have this:
Root1
---Water
---Dirt
-----Fire
-----Stone
---UFOs
Root2
---Acid
-----H20
-----TNT
And put all into one "Megaroot"
MEgaRoot
---Root1
------Water
------Dirt
--------Fire
--------Stone
------UFOs
---Root2
------Acid
--------H20
--------TNT
Maybe it is easy, but it is one of those days when i havo no idea how to approach to this.
Thank you all for the response
PROBLEM SOLVED:
Dim Counter As Integer = trvItems.Nodes.Count
Dim oldRoot As TreeNode
Dim newRoot = New TreeNode("Megaroot")
For i As Integer = 0 To Counter - 1
oldRoot = trvItems.Nodes(0)
trvItems.Nodes.Remove(oldRoot)
newRoot.Nodes.Add(oldRoot)
Next i
newRoot.Expand()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要从树中删除旧的根,以便给它一个新的父级。创建一个新根,然后将旧根添加到其中。像这样:
You need to remove the old root from the tree so you can give it a new parent. Create a new root then add the old one to it. Like this: