how to declare MyTreeNodeCollection Class

JFK

Member
Joined
Nov 28, 2005
Messages
20
Location
Czech Republic
Programming Experience
5-10
Hi to all,

I have a lot of additional information about my TreeNodes, which I am storing in extra array. Because it's not too comfortable and quick to search information every time I wanted to find something about TreeNode, I decidet to make my own TreeNode class and add some own properties in it.

Now I would like to force TreeView to use MyTreeNode instead of TreeNode class.

I made MyTreeView class, which inherits from TreeView, but I'm not sure, how to declare own class MyTreeNodeCollection and its Sub New, which I, by VS.NET, have to.

Can anyone help me?

Thaks, #JFK

 
You can't inherit the TreeNodeCollection, I don't know if it is possible to mimic the behaviour with a plain CollectionBase.

You do know the standard Treeview (or one inherited from it) will accept your custom inherited TreeNodes ?
 
Solution

Thans a lot for your answer, fortunately I have already solved this problem.

I found on address: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtsksubclassinglistitemortreenode.asp

proper information and realised, that it is not neccesary to make new TreeNodeCollection in my case.

Only thing, I have to do, is to retype TreeNode into MyTreeNode class (object) every time, I want to work with MyTreeNode instead of TreeNode.

so instead of:

VB.NET:
TreeView.Nodes.Add("node text")
I have to use:

VB.NET:
TreeView.Nodes.Add( New MyTreeNode ("node text"))


and while working with MyTreeNode I should use for example:

VB.NET:
Ctype(TreeView.SelectedNode, MyTreeNode).MyProperty = "something"



And it´s all.

#JFK
 
That is right, you could also add methods and properties to an inherited Treeview to accept only myTreenode and return nodes of specific type myTreenode. (ie .myAdd method and .mySelectedNode property)
 
Back
Top