search - 我的表单中的基本搜索,但有所不同
问题描述
我有一个组框,其中包含一个显示一堆 .txt 文件的列表框。在这个组框中还有一个文本框,我想用它来搜索文件列表。我已经在我的文本框 textchange 事件中添加了一些代码,但它所做的只是清除我的列表框,并且在退格键上,列表框没有重新填充它显示的 .txt 文件?蚂蚁帮助将不胜感激,thanx
private void custsearchbox_TextChanged(object sender, EventArgs e)
{
var itemList = custList.Items.Cast<string>().ToList();
if (itemList.Count > 0)
{
//clear the items from the list
custList.Items.Clear();
//filter the items and add them to the list
custList.Items.AddRange(
itemList.Where(i => i.Contains(custsearchbox.Text)).ToArray());
}
}
解决方案
这有效:
listsup.Items.Clear();
Supfile = System.AppDomain.CurrentDomain.BaseDirectory + "data\\Suppliers.txt";
List<string> proName = new List<string>();
using (StreamReader rdr = new StreamReader(Supfile))
{
string line;
while ((line = rdr.ReadLine()) != null)
{
if (line.ToString().ToLower().Contains(supsearchtxt.Text))
{
string[] val = line.Split(',');
listsup.Items.Add(val[0]);
}
}
}
推荐阅读
- javascript - await 不能按预期在nodejs项目上工作
- python - 使用 Geany IDE 找不到加密模块
- docker - 如何在使用 docker 时禁用 Portainer 上的 CLI?
- architecture - 基于云的虚拟实验室环境架构
- javascript - 将代码部署到 gh-page 后,React 门户不起作用
- odoo - Odoo studio:如何在 o2m 或 m2o 字段中设置模型的值
- azure - 如何在 Azure 上部署 rustici 引擎?
- php - 我收到一个错误“您必须启用 intl 扩展才能使用 CakePHP。”
- reactjs - 没有合适的加载器来处理 js WebPack babel-loader
- c++ - 为什么不允许在函数声明和定义中使用默认参数?