yanleigis的专栏

闫磊 GIS

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

 

//查找可见项

  private TreeNode GetNode(TreeView tv, TreeNode StartNode, String str)
        
...{
            
//by 闫磊 Email:Landgis@126.com,yanleigis@21cn.com 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:Landgis@126.com,yanleigis@21cn.com 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;

        }

 

阅读更多
个人分类: C#
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

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

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭