Access the answers to your technology questions today.
Subscribe Now
30-day free trial. Register in 60 seconds.
What Makes Experts Exchange Unique?
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.
Try it out and discover for yourself.
Subscribe Now
30-day free trial. Register in 60 seconds.
Join the Community
Give a Little. Get a Lot.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Join the Community
by: Mikal613Posted on 2004-02-09 at 09:49:13ID: 10312298
There doesn't appear to be something like that specifically in the .NET TreeView. Is there a particular case when you need that? If you're using it in response to an event the tree fires, the event probably gets a TreeViewEventArgs parameter. As part of the TreeViewEventArgs class, you get the node that is being affected by the event, so that may address the cases when you need to find the tree entry.
iew treeView; // defined on your form.
However, you can simulate your request by using a HashTable to cache a pointer to the node in the TreeView. When you add a new node to the tree, also add it to a mapping HashTable. Then, you can retrieve a tree node quickly.
private System.Windows.Forms.TreeV
private Hashtable keyList = new Hashtable();
// create a new tree item.
TreeNode node = new TreeNode("ItemXX");
keyList.Add("ItemXX", node);
Then, you can access the nodes in the tree by the hash key. In this case, I used the name, but you can use whatever you'd like.
TreeNode myNode = keyList["ItemXX"];