I have a TreeView on my winform which uses a subclass of TreeNode with some additional variables I want to store against each node. Users can delete nodes from my tree using a context menu.
What I'd like to be able to do is extend the Remove method for TreeNode so that I do some extra processing in there before the node is removed. Is there a way to do this?
To clarify...
Is there a way to extend the existing Remove method for TreeNode so that code can be executed before it's actually does the remove?
Cheers,
EDIT: Im actually assuming that the way i'll have to do this is extend the class with a new method which calls this.Remove() instead?
EDIT 2: This is what I ended up doing. Is it the best way...
public partial class CustomTreeNode : TreeNode
{
// My custom TreeNode vars
public int UID;
public int ParentUID;
public CustomTreeNode(string nodeName) : base(nodeName)
{
// Set the tree node here
}
public void RemoveIt()
{
// Custom stuff
System.Console.WriteLine("Deleted");
base.Remove();
}
}