I have a treeview control on a form.
The TreeView control automatically as part of the .NET framework contains and uses a TreeNodeCollection, which of course you gain access to using objTreeView.Nodes
I am able to override the TreeView control without breaking the tinyest of a sweat.
Public Class MyOwnTreeView
Inherits System.Windows.Forms.TreeView
...
End Class
Well here's the EEEnormously HUUUUUGE dilemma where MASSIVE brain power would be required to solve...
Now that I have inherited the treeview control and overridden various methods/properties in it, I also want to override the TreeNodeCollection that the treeview uses internally and that I only have access to through me.Nodes from within the treeview's overridden code. How can I possibly override the TreeNodeCollection and force my overriden treeview to also use my overridden TreeNodeCollection instead of it's own.
Answer that and you probably make $100k+ per year and have a kicka$$ house and car, along with my massive praise and respect.
Thanks.

If you can answer this Overrides Question... you're brilliant and probably way underpaid
Satyajit Mahapatra
Well, I would have thought that if you were to override the Nodes property, you'd be able to override the collection that it uses, actually.
However, I also think that responsibility for how a node is drawn belongs to the node, not the collection that holds it.
Roinka
See my next post below for what I am trying to resolve...
THanks.
Dave.
Raymond1980
Just for our own amusement, how would you intercept the calls to Add(), Insert(), Remove() without a "hack" since you think my solution was a hack
I assume you would add your own said procedures to the derived class and then have something like...
TreeView.Add()
TreeView.Remove()
TreeView.Insert()
TreeView.Nodes.Add()
TreeView.Nodes.Remove()
TreeView.Nodes.Insert()
Talk about the pot calling the kettle black. If that's not what you propose, then I apologize. If it is, you've simply demonstrated that you're no smarter than me, hence you better do some studying yourself. Overriding a class within a class is obviously the best solution and obviously not available because the .NET developers didn't include this clean solution.
Samie_ug
The problem I want to resolve is simply to put responsibility where it belongs. I have nodes that I color based upon not just their state when they are placed in a treeview, but if they are dragged and dropped to different locations in the tree, they should immediately reflect their newly computed forecolor and backcolor settings automatically. Well it seemed to me that the easiest place to colorize nodes to reflect their position/state in the tree would be to override the Nodes.Add
This would catch nodes that were simply added to the tree, as well as nodes that are repositioned through a drag/drop because drag/drop removes the node from one spot and add's it to another.
Well, I am quickly beginning to think that a cheesy stupid sloppy hack is the only way to solve this since I don't seem to be allowed to override a class within a class (TreeView.TreeNodeCollection) because the .NET developers weren't smart enough themselves to account for something that should be incredibly necessary and obvious. And I'm not even that experienced of a programmer. If anyone should see the need to override classes within classes, its the .NET developers... which is really hurting my respect for these folk.
Thanks
Dpowers
You can override the TreeNode class itself, if you want to, and add instances of your new class as treenode items. Will that help solve your problem
bleu
I have looked thoroughly at all the events that the treeview raises because amazingly a TreeNode does not raise any events. You may be right on the responsibility being with the node itself, in which case I will override the TreeNode class and raise some events I guess that hopefully will capture every scenario where a color might need to change.
I do still believe though that being able to override classes within classes should be an achievable and necessary feature of .NET programming. The only alternative in many cases is a sloppy greasy hairy fat ugly hack that looks like the grill of a Cadillac Escalade slapped onto the front of a 1968 Camaro, or a row of gold teeth on a welfare- dependent trailer-park livin wannabe rapper.
And no... I looked, Nodes does not appear in the overrides list for the control.
Lidya
I would suggest the best answer is to spend your efforts improving your understanding of proper application design and use of the Framework rather than wasting it on incorrect statements.
Your original solution is far more of a "hack" than any of the more appropriate designs you seem to be so offended by.
vino-msdba
You will not be able to replace the collection the native TreeView control uses. At best, you can create a buffer layer in your derived class where you handle all Node-related calls (AddNode, etc...), handling them special as needed.
Your request begs the question: What specific problem are you trying to resolve with this