将节点添加到 C# TreeView 控件时如何运行代码

发布于 2024-12-06 07:20:46 字数 129 浏览 0 评论 0原文

当将新节点添加到树视图控件时,我需要运行代码。当将新节点添加到 TreeView 时,控件附带的 Control_Added 事件不会被触发,这很奇怪,因为我期望它是一个控件,我的意思是一个节点。为此应该使用什么事件?

谢谢..

I need to run code when a new node is added to a treeview control. Control_Added event that comes with the control does not get fired when a new node is added to the TreeView which is weird as I expected that it was a control, a node I mean. What event should be used for this?

Thanks..

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

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

发布评论

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

评论(1

卖梦商人 2024-12-13 07:20:46

没有为此举办的活动。这并不罕见,事件旨在告诉您的代码发生了一些您感兴趣的事情,一些您不知道的事情。您的程序的用户无法向树视图添加节点,只有您的代码可以做到这一点。你已经知道了。

解决方法是从 TreeView 继承一个类并添加所需的事件,以及添加节点并引发事件的公共帮助器方法。这不是一个很好的后门,因为仍然有一个后门可以添加您无法轻易关闭的节点。

There is no event for that. This is not unusual, events are meant to tell your code that something of interest happened, something you don't otherwise know about. The user of your program cannot add a node to the treeview, only your code can do that. You already know about it.

Inheriting a class from TreeView and adding the event you want, as well as a public helper method that adds the node and raises the event is the workaround. It isn't a very good one because there is still a backdoor to add nodes that you cannot easily close.

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