Newbie: How to get the handle of a TreeNode

J

Jeff

IDE: Visual Studio 2003 .Net
OS : XP Pro

Is there a way to get the handle to a specific node in the treeview based on
the value of TreeNode.Tag, without having to travarser through the tree???

to solve the problem, I am trying this (I don't yet know if this is the
correct approach):
TreeNode tn2 = new TreeNode();
tn2.Tag = "Home";
TreeNode t3 = tn2.FromHandle(treeView1, tn2.Handle);

But I get these errors:
1)
System.Windows.Forms.TreeNode.FromHandle(System.Windows.Forms.TreeView,
System.IntPtr)' cannot be accessed with an instance reference; qualify it
with a type name instead

2)
The type or namespace name 'tn2' could not be found (are you missing a using
directive or an assembly reference?)

Any clues will be appreciated!

Jeff
 
N

Nicholas Paldino [.NET/C# MVP]

Jeff,

No, there is no way to do this. The Tag property is a way of you
assigning a user-defined piece of data to the node, the TreeView itself has
no clue how to handle what is in that property. That part is left to you.

What you could do is have a hashtable which is keyed on the contents of
the Tag property, and the values are the nodes itself.

You are getting the error because you are trying to call FromHandle,
which is a static method, on an instance object. You have to call it like
this:

// Get the node.
TreeNode t3 = TreeNode.FromHandle(treeView1, tn2.Handle);

Hope this helps.
 

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