如何同时删除两个TreeNode
我有一个 TreeView,我想同时删除它的 2 个节点。
node.Remove();
这将删除该节点,但在此代码之后,将自动选择下一个节点。有办法防止这种情况吗?或者对我来说更好的解决方案是在删除前一个节点后立即删除下一个节点。
你可能会问为什么。在我的程序中,每对节点都是执行某些操作所必需的。因此,如果我删除其中一个,TreeView 控件将跳转到该对的下一个成员,并且由于最后一个被删除,我的所有代码都会出错,因为它无法再找到该节点。
如果您需要更多信息,请告诉我。
I have a TreeView and I want to remove 2 nodes of it at the same time.
node.Remove();
This will delete the node, but after this code the next node will automatically selected. Is there a way to prevent that? Or better soloution for me will be deleting the next node right after its pervious node is deleted.
You may ask why. In my program every pair of nodes are necessery for doing something. so If I delete one of them, TreeView control will jump to next member of that pair and because the last one is deleted, all my codes goes wrong since it can not find that node anymore.
Please let me know if you need more info.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我很幸运......我的节点文本每对节点都以“_1”和“_2”结尾,所以我想出了这个解决方案:
Ok, I was lucky...My node texts are ending in "_1"and "_2" for each pair of nodes so I came up with this soloution:
通过简单的树视图和简单的上下文菜单,这对我有用
With simple tree view and a simple context menu this works for me