使用文本框值突出显示到树视图节点 [英] highlighted to tree view node using text box value

查看:72
本文介绍了使用文本框值突出显示到树视图节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用波纹管代码找到并突出显示树节点值。我必须给出完整的节点值作为搜索文本。所以我需要给出部分节点值并突出显示给定文本的所有节点匹配。有人可以帮助我。



我的代码

  private   void  button2_Click( object  sender,EventArgs e)
{
FindByText();
}
私有 void FindByText()
{
TreeNodeCollection nodes = treeView1.Nodes;
foreach (TreeNode n 节点中)
{
FindRecursive( N);
}
}

私有 void FindRecursive( TreeNode treeNode)
{
foreach (TreeNode tn in treeNode.Nodes)
{
// 如果文本属性匹配,请为项目着色
if (tn.Text == this .textBox.Text)
{
tn.BackColor = Color.Yellow;

}
FindRecursive(tn);
}
}



问候

Ruwan Atapattu

解决方案

您可以使用:

  if (tn.Text.Contains(textBox1.Text))
{
tn.BackColor = Color.Yellow;

}

我建议你创建一个变量,将搜索字符串保存在递归过程之外,以优化搜索...如果你在大量的TreeNodes上进行搜索。



我发现你的代码检查TreeView的根级节点:这是一个设计决定吗?


I am find and highlighted tree node value using bellow code. I had to give full node value as search text.So i need to give part of the node value and highlighted all the node match to given text. Can some one help me.

MY code

private void button2_Click(object sender, EventArgs e)
{
FindByText();
}
private void FindByText()
       {
           TreeNodeCollection nodes = treeView1.Nodes;
           foreach (TreeNode n in nodes)
           {
               FindRecursive(n);
           }
       }

       private void FindRecursive(TreeNode treeNode)
       {
           foreach (TreeNode tn in treeNode.Nodes)
           {
               // if the text properties match, color the item
               if (tn.Text == this.textBox.Text)
               {
                   tn.BackColor = Color.Yellow;
                  
               }
               FindRecursive(tn);
           }
       }


Regards
Ruwan Atapattu

解决方案

You can use:

if (tn.Text.Contains(textBox1.Text))
{
    tn.BackColor = Color.Yellow;

}

I'd suggest you create a variable to hold the search string outside your recursive procedure to optimize the search ... if you are doing searches across large numbers of TreeNodes.

I observe that your code does not examine the root-level Nodes of the TreeView: is that a design decision ?


这篇关于使用文本框值突出显示到树视图节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆