.net C# Treeview的查找node文字项

 

//查找可见项

   private  TreeNode GetNode(TreeView tv, TreeNode StartNode, String str)
        
{
            
//by 闫磊 Email:[email protected],[email protected] 2007.10.10
            TreeNode Node;
            str 
= str.ToUpper();
            
if (StartNode == null)
            
{
                Node 
= tv.Nodes[0];
            }

            
else
            
{
                Node 
= StartNode.NextVisibleNode;
            }

            String Text;
            
int p;
            
while (Node != null)
            
{
                Text 
= Node.Text.ToUpper();
                p 
= Text.IndexOf(str);
                
if (p > -1)
                
{
                    
return Node;
                }

                Node 
= Node.NextVisibleNode;
            }

            
return null;
        }

 //查找所有项

//Accurately是否为精确查找

private TreeNode GetNode(TreeView tv, TreeNode StartNode, string str, bool accurately)

        {

            //by 闫磊 Email:[email protected],[email protected] 2007.10.10

            TreeNode Node;

            if (str == null) return null;

            str = str.ToUpper();

            if (StartNode == null)

            {

                Node = tv.Nodes[0];

            }

            else

            {

                Node = StartNode.NextVisibleNode;

            }

            String Text;

            int p;

           TreeNode ParentNode = Node;

            while (Node != null)

            {

                if (accurately)

                {

                    if (str == Node.Text)

                        return Node;

                }

                else

                {

                    Text = Node.Text.ToUpper();

 

                    p = Text.IndexOf(str);

                    if (p > -1)

                    {

                        return Node;

                    }

                }

               

                if (Node.GetNodeCount(true) > 0) //有子               

                {

                    ParentNode = Node;

                    Node = Node.Nodes[0];

                }

                else

                {

                    Node = Node.NextNode;

                    while ((Node == null) && (ParentNode != null))

                    {

                        Node = ParentNode.NextNode;

                        ParentNode = ParentNode.Parent;

                    }

 

                }

             

            }

            return null;

        }

 

你可能感兴趣的:(.net,String,C#,null,email)