Use value to find the Treeview node and select

Source: Internet
Author: User

/// <Summary>
/// Search for a specified Node
/// </Summary>
/// <Param name = "tnparent"> node </param>
/// <Param name = "strvalue"> value </param>
/// <Returns> </returns>
Private treenode findnode (treenode tnparent, string strvalue)
{
Treenode treenode2 = new treenode ();
String venuecode = "";
If (tnparent = NULL) return NULL;
If (tnparent. value = strvalue) return tnparent;
Tnparent. Expand ();
Treenode tnret = NULL;
Foreach (treenode tn in tnparent. childnodes)
{
// Obtain the node Value
If (venuecode = "")
{
// Record the node
Treenode2 = tn;
Venuecode = tn. value;
}
Else
{
// When the selected node changes
If (venuecode! = Tn. value)
{
Treenode2.collapse ();
Venuecode = tn. value;
Treenode2 = tn;
}
}

Tnret = findnode (TN, strvalue );
If (tnret! = NULL) break;
}
Return tnret;
}

The method is called as follows:
// Search nodes cyclically

Foreach (treenode node in this. treeview1.nodes)
{
Treenode = findnode (node, venuecode );

If (treenode! = NULL)
{
Treenode. collapseall ();
Treenode. Selected = true;
State = 1;
Break;
}
}

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.