Another method for locating TreeView nodes in Winform: TreeNode. FromHandle

Source: Internet
Author: User

TreeView in Winform is a common and powerful control. Generally, you may be familiar with it. It is estimated that most of us are doing node locating, this method is usually used for loop search. The method is as follows:

Foreach (TreeNode node in this. TreeView1.Nodes)
{
If (node. Text = "Name of the node to be found ")
{
Return node;
}
Return null;
}

 

Another method is to use TreeNode. to illustrate how to use the FromHandle method to quickly locate nodes, we assume that there is a group in which there are many companies and each company has some subsidiaries,

We need to add some device nodes or personnel nodes under each subsidiary. So how should we deal with the display and positioning of these nodes?

First, we record the tree node information of these companies and their subsidiaries when adding nodes to the group and put them in the memory list. The Code is as follows.

TreeView treeView = this. TreeView1;
TreeView. Nodes. Clear ();
Foreach (string key in groupList. Keys)
{
TreeNode node = treeView. Nodes. Add (key, key, 0 );
If (! CompanyHandleDict. ContainsKey (key ))
{
CompanyHandleDict. Add (key, node. Handle );
}
}

Foreach (string key in groupList. Keys)
{
Foreach (string subKey in groupList [key]. Keys)
{
TreeNode node = TreeNode. FromHandle (treeView, companyHandleDict [key]);
If (node! = Null)
{
TreeNode tempNode
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.