A node of the Treeview is selected by default-correction method

Source: Internet
Author: User
Thanks high_mount for pointing out my previous article Article By default, the method written in the method of selecting a node in the Treeview method is incorrect. This method can only be used in the case of less than three layers. I will modify this method to apply to any number of layers. Code As follows:

/**/ /// <Summary>
///To select a node of the Treeview, the value of each node must be different.
/// </Summary>
/// <Param name = "snodevalue"> </param>
Private   Void Selectnode (Treeview TV, String Snodevalue)
{
Foreach (Treenode troot In TV. nodes)
{
If (Troot. Value = Snodevalue)
{
Troot. Select ();
}
Else
{
If (Troot. childnodes ! =   Null )
{
// Foreach (treenode tchild in troot. childnodes)
// {
// If (tchild. value = snodevalue)
// Tchild. Select ();
// }
Treenode ttmp =   Null ;
Ttmp = Findnode (troot, snodevalue );
If (Ttmp ! =   Null )
Ttmp. Select ();
}
}
}
}

/**/ ///   <Summary>
/// Recursive search for parent nodes
///   </Summary>
///   <Param name = "tnparent"> Specify a root node and traverse it </Param>
///   <Param name = "strvalue"> Value of the node to be searched </Param>
Private Treenode findnode (treenode tnparent, String Strvalue)
{
If (Tnparent =   Null ) Return   Null ;
If (Tnparent. Value = Strvalue) Return Tnparent;
Treenode tnret =   Null ;
Foreach (Treenode TN In Tnparent. childnodes)
{
Tnret=Findnode (TN, strvalue );
If(Tnret! = Null)Break;
}
Return Tnret;
}

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.