how do I run code when a node is added to a C# TreeView control
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..
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.
精彩评论