Creating a new TreeNodeCollection (and getting handles,...)

N

NoLongerMicah

I have derived new classes for the TreeNode and TreeView classes that
Microsoft provides. Since the TreeNodeCollection class is sealed I
created my own class that implements the IList interface.

However, the original TreeNodeCollection class does something
important on the "Add" method where it assigns the "TreeView" and
"Handle" to the TreeNode object that you are adding. I need this
information - and can not figure out how they are doing this.
Needless to say - my class that I created does not do this.

Does anyone have some code for Microsoft's implementation of the
TreeNodeCollection class - or does anyone have any idea of where I
should start?

It is very annoying that they sealed this class (with internal
constructor)...
 
N

NoLongerMicah

This is the way I got around the problem. I'm not thrilled that it's
the best solution, but it does work...

public class ICNodeCollection
{
private TreeNodeCollection nodes;

public ICNodeCollection(TreeNodeCollection treeNodes)
{
nodes = treeNodes;
}
.... (add special functions for NodeCollection class)
}

public class ICTreeNode : System.Windows.Forms.TreeNode
{
private ICNodeCollection nodes;

public ICTreeNode() : base()
{
nodes = new ICNodeCollection(base.Nodes);
}

....
}

public class ICTreeView : System.Windows.Forms.TreeView
{
private ICNodeCollection nodes;

public ICTreeView() : base()
{
nodes = new ICNodeCollection(base.Nodes);
InitializeTreeView();
}
...
}

It's just annoying that Microsoft did not allow us to derive from the
TreeNodeCollection class.
 
N

NoLongerMicah

This is the way I got around the problem. I'm not thrilled that it's
the best solution, but it does work...

public class ICNodeCollection
{
private TreeNodeCollection nodes;

public ICNodeCollection(TreeNodeCollection treeNodes)
{
nodes = treeNodes;
}
.... (add special functions for NodeCollection class)
}

public class ICTreeNode : System.Windows.Forms.TreeNode
{
private ICNodeCollection nodes;

public ICTreeNode() : base()
{
nodes = new ICNodeCollection(base.Nodes);
}

....
}

public class ICTreeView : System.Windows.Forms.TreeView
{
private ICNodeCollection nodes;

public ICTreeView() : base()
{
nodes = new ICNodeCollection(base.Nodes);
InitializeTreeView();
}
...
}

It's just annoying that Microsoft did not allow us to derive from the
TreeNodeCollection class.
 
N

NoLongerMicah

This is the way I got around the problem. I'm not thrilled that it's
the best solution, but it does work...

public class ICNodeCollection
{
private TreeNodeCollection nodes;

public ICNodeCollection(TreeNodeCollection treeNodes)
{
nodes = treeNodes;
}
.... (add special functions for NodeCollection class)
}

public class ICTreeNode : System.Windows.Forms.TreeNode
{
private ICNodeCollection nodes;

public ICTreeNode() : base()
{
nodes = new ICNodeCollection(base.Nodes);
}

....
}

public class ICTreeView : System.Windows.Forms.TreeView
{
private ICNodeCollection nodes;

public ICTreeView() : base()
{
nodes = new ICNodeCollection(base.Nodes);
InitializeTreeView();
}
...
}

It's just annoying that Microsoft did not allow us to derive from the
TreeNodeCollection class.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top