且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

只要创建一个新的节点是树视图添加事件处理程序

更新时间:2023-11-30 09:31:22

不幸的是,因为TreeNodeCollection实际上是一棵树,我想你会被卡住需要从头本质上实现自己的树型视图,用自定义的树数据结构与事件,或寻找第三方或开源之一来使用。

Unfortunately, since TreeNodeCollection is in fact a tree, I think you're going to be stuck needing to implement your own tree view control essentially from scratch, with a custom tree data structure with events, or finding a third-party or open source one to use.

如果它是一个简单的集合,我会说只是包装在一个自定义用户控件的框架TreeView控件,并隐藏节点属性,只露出你想要的存取函数。然后,你可以只是之前和/或通过传递调用底层的TreeView控件后解雇你的控件的事件。然而,这只会给你的事件节点的第一层上。

If it were a simple collection, I'd say just wrap a framework TreeView control in a custom user control, and hide the Nodes property, exposing only the accessors and mutators you want. Then you could just fire your control's events before and/or after passing the calls through to the underlying TreeView control. However, this would only give you events on the first layer of nodes.

这很容易使一个列表或字典类突变事件,因为你可以只是包装他们这样。但树是皇家疼痛有落实,特别是如果你要分发或出售使用它的code。不幸的是,我们得到他们基本上没有帮助从.NET框架。因为实现一个树形结构的所有复杂的,我会的强烈建议试图找到一个pre-制作解决方案,无论是第三方或开源的。

It's easy to make a List or Dictionary class with mutator events, because you can just wrap them like that. But trees are royal pain to have to implement, especially if you're going to distribute or sell the code that uses it. And unfortunately, we get essentially no help with them from the .NET framework. Because of all the complexities of implementing a tree structure, I would strongly recommend trying to find a pre-made solution, either third-party or open source.