TreeView and TreeNode problem

  • Thread starter Thread starter pei_world
  • Start date Start date
P

pei_world

I wrote a class inherit from TreeNode of the system as follow, but when I
try to use it with TreeView object, then it doesn't work, can anyone help?

//============== code to use the inherited node
ServiceServer.InheritTreeNode rootNode = null;
rootNode = treeServices.Nodes.Add(System.Net.Dns.GetHostName());
//*** Error: Cannot implicitly convert type 'System.Windows.Forms.TreeNode'
to 'ServiceServer.InheritTreeNode'



//============== inherit class
public class InheritTreeNode:TreeNode
{
public enum NodeType
{
root,
subroot,
content
}
private NodeType nodetype;
......
......
 
You need to cast the tree node:

rootNode = (InheritTreeNode)
treeServices.Nodes.Add(System.Net.Dns.GetHostName());

But that still won't do what you think it should because the node added is
actually created by the Add method. In other words just casting it isn't
going to give you magically an inherited node since the method didn't create
that.

+++ Rick ---

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
 
To accomplish that, you also should create your own TreeView, by inheriting
from the default TreeView, so you'd have control over the Add method etc.
 

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

Back
Top