Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
working from my treeview mention in Treeview ownerdrawtext bound[^] I also want to add propertys to the treeviewnodes. So I want to extend the existing treenode with those so that I can paint them like I want.

What I have tried:

Already tryed creating a new usercontrol myNode with Inherits TreeNode But that way I can't add the nodes
Posted
Updated 19-Apr-21 7:27am

If deriving a class from TreeNode[^] isn't possible for some reason - and I've not tried it but I'd have thought it was fairly easy but I could be missing something - then the simplest way to do it is to use the Tag property that every Control derived class has.

Tag is a Object that is free for your use, and which can contain an instance of any class - so create a class which contains the properties you need as a stand-alone class, create an instance of it, fill out the details, and assign a fresh instance to each TreeNode.Tag.

Then when you want to paint it, cast current TreeNode.Tag back to your properties class, and you have access to the info you need without having to derive a new class from TreeNode.


But derivation is normally a better approach - what problems did it give you?
 
Share this answer
 
I really hoped it was possible.
However I was already thinking of doing it your way.
So I have a very simple class that I add to the tag. in the drawnode I test of the tag is of my new class and al is working. I even created a public function in the treeview to get the current treeviewsettings. So I have only to adapted the setting before adding them to the tag.

Thanks
Jan
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900