I have a class that extends TreeNode in .NET 3.5 (C#), LocationNode. This class is a TreeNode but contains some additional data points for easy extraction. The TreeView that these LocationNode objects are displayed in has Drag & Drop functionality implemented. Each LocationNode object has a dirty flag that indicates whether any of the data points I care about were changed by the user. Coincidentally, one of the data points that I care about is the parent node.
I could implement some functionality into the Drag & Drop code to determine if the parent node has changed easy enough, but for abstraction sake I would like the LocationNode objects to track their own dirty flag and set it to true when necessary.
Is there any way to know if the parent node has changed? I don’t see any events that I can hook into from LocationNode that would alert me when it has been added or removed from a collection.
Ideas?
When you add the node to the treeview, store its parent (or parent.fullpath), then when you do your dirty calculation compare the current parent to the stored. Then in your SetClean() function, store the current parent again.