I was thinking about inheritance and inheriting from a treenode. Is it possible to create a new class, inherit all from a treenode, and then use the new class to insert a node into a treeview? If so, how would I go about this?
The main reason I want to do this is for more .Tag properties.
Taco, I use .NET 2003, but I don't think a ton has changed in this area..
You can use a custom treenode, but you will need to directcast it as the custom class at some points, or you can create a custom class that will sit in the tag of a regular tree node (as a tag is of type object and can hold any .net object)
here is an example. Its in 2003, but 2005 should be able to open it fine.
Ahha, now I see where you need directcast. I have never used that before. Ok, I have tried to add a new node of type treenodeplus to my treeview but it tells me I cannot because of wrong type. I tried ctype once but nothing. If I used directcast on the treenodeplus node to add it into the treeview would that work?
If your TreeNodePlus class inherits the TreeNode class then there is no reason that you should not be able to add it to a TreeView. You have to add a TreeNode to a TreeView's Nodes property and a TreeNodePlus object IS a TreeNode. You should only have to cast the object when you RETRIEVE it from the TreeView because it will be returned as a TreeNode reference. As an example, assume you go to a recruitment company who place programmers. They can place you because you are a VB.NET programmer, which inherits programmer. When someone gets you from the recruitment company they are getting a programmer, so they would need to tell everyone that you are a VB.NET programmer so that people would know that they could use your VB.NET skills.