编辑 TreeView 节点不会更改 TreeNode 键

发布于 2024-08-30 07:40:50 字数 460 浏览 6 评论 0原文

我有一个带有用户可编辑节点的 TreeView。我喜欢使用节点标题作为我的树节点的键:

+ Root
|+ Node1
||- SubNode1
||- SubNode2
|+ Node2
||- SubNode3
||- SubNode4

所以我可以到达这样的节点:

MyTreeView.Nodes["Root"].Nodes["Node2"].Nodes["SubNode3"]

问题是,当我允许用户重命名任何节点时,我还需要更改我的节点的键它的父级在 AfterLabelEdit 处理程序中...这似乎(逻辑上)不会自动完成。 不幸的是, Nodes["blabla"] 是只读的,Nodes.Add(string Key, TreeNode Node) 不存在,而且我找不到一种方法来做到这一点而不抛出(迟早)一个糟糕的异常。

有什么想法吗?

I have a TreeView with user-editable nodes. I like to use the node caption as key to my tree node :

+ Root
|+ Node1
||- SubNode1
||- SubNode2
|+ Node2
||- SubNode3
||- SubNode4

So I can reach a node like this:

MyTreeView.Nodes["Root"].Nodes["Node2"].Nodes["SubNode3"]

The problem is that, as I allow the user to rename any node, I would need also to change the key of my node in its parent in the AfterLabelEdit handler... which seems (logically) not to be done automatically.
Unfortunately, Nodes["blabla"] is readonly, Nodes.Add(string Key, TreeNode Node) doesn't exist, and I can't find a way to do this without throwing (sooner or later) a bad exception.

Any idea ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮年 2024-09-06 07:40:50

好吧,更改 Node.Name 属性似乎有效......

Well, changing the Node.Name property seems to work...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文