最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

C#:从树视图中搜索

SEO心得admin47浏览0评论
本文介绍了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; } }

推荐答案

您需要注册文本更改事件:msdn.microsoft/en-us/library/system.web.ui.webcontrols.textbox.textchanged.aspx

you need to register to the text changed event: msdn.microsoft/en-us/library/system.web.ui.webcontrols.textbox.textchanged.aspx

以及查找特定节点使用:

and for finding the specific node use:

treeView1.Nodes.Find()

此处的模式详细信息:msdn.microsoft/en-us/library/system.windows.forms.treenodecollection.find

发布评论

评论列表(0)

  1. 暂无评论