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;
}