如何删除树节点并将其节点节点向上移动?
实际上在我的树视图中,当我删除一个树节点时,它会删除它的所有子节点,但我需要向上移动它的子节点而不是删除。我必须在c Sharp的winforms中使用。
任何人都可以帮帮我。
Actually in my treeview ,when i remove a tree node it removes all its child node, But i need to move its child node upwards instead of removing .I have to use in winforms in c sharp.
Anybody help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
那么您只想删除一个节点并保留任何子节点?
您要做的是:
So you just want to remove a node and keep any childnodes?
What you have to do is:
狂想曲说的话。
这是一个例子:
What Rhapsody said.
And here is an example:
您遇到的问题是由任何给定节点的子节点存储在 myNode.Nodes 中这一事实引起的。因此,当您删除一个节点时,它的所有节点也会被释放,因此您必须首先迭代子节点,移动它们,然后删除原始节点:
The problem you're having is caused by the fact that the child nodes of any given node is stored in
myNode.Nodes
. So, when you remove a node all of its nodes are freed as well, so you will have to first iterate through the child nodes, move them, then remove the original node:您可以循环遍历子节点并将它们添加到节点的父节点,然后再删除节点本身。此代码应该处理要删除的节点是父节点的情况。
You can loop through the child nodes and add them to the node's parent before removing the node itself. This code should handle cases where the node to be removed is a parent node.