C#:从树视图中搜索 [英] C#:Search from treeview
本文介绍了C#:从树视图中搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从 XML 文件加载了一个树视图数据.我想在用户在文本框中键入内容时执行搜索.这是正确的做法吗??我只想过滤数据.请给我举个例子.
I got a treeview data loaded from a XML file. I want to perform a search when the user types something in the textbox. Is that the right way of doing it?? I just want to filter the data. Please show me some example.
以下代码无效.
textBox1.Enter += new EventHandler(txtSearch_TextChanged);
private void txtSearch_TextChanged(object sender, EventArgs e)
{
foreach (TreeNode node in this.treeView1.Nodes)
{
if (node.Text.ToUpper().Contains(this.textBox1.Text.ToUpper()))
{
treeView1.SelectedNode = node;
break;
}
}
推荐答案
您需要注册文本更改事件:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.textchanged.aspx
you need to register to the text changed event: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.textchanged.aspx
以及查找特定节点使用:
and for finding the specific node use:
treeView1.Nodes.Find()
此处的模式详细信息:http://msdn.microsoft.com/en-us/library/system.windows.forms.treenodecollection.find
这篇关于C#:从树视图中搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文