c# - 在不更改 DataGridView 表的情况下搜索 DataGridView
问题描述
我有DataGridView
一些数据。我也有一个搜索TextBox
,当它的文本发生变化时,我想在DataGridView
不更改原始数据的情况下进行搜索DataGridView
。
当客户编写他的搜索行时,DataGridView
将执行以下选项之一:
- 仅显示与搜索行匹配的行,
- 或将客户端跳转到该行并突出显示它(优于 1)。
在 StackOverflow 上搜索时,我可以找到类似的案例,但无法在我的程序中应用他们的任何解决方案。
这是我到目前为止的代码:
private void search_TextChanged(object sender, EventArgs e)
{
(dataGridView1.DataSource as DataTable).DefaultView.RowFilter =
string.Format("name = '{0}'", search.Text);
}
但它只显示一个空,DataGridView
虽然我应该有一个结果。
我添加到我的 Fund 类函数中搜索列表中的所有名称:
public static List<Fund> findFundbyName(string name)
{
return funds.Where(c => c.name.Contains(name)).ToList();
}
然后在更新时DataGridView
我使用了这个功能:
if (search.Text != "")
{
table = ConvertListToTable(Fund.funds, search.Text);
}
else
{
table = ConvertListToTable(Fund.funds, "");
}
解决方案
推荐阅读
- android - 更新后Android重启应用程序
- c++ - 查找蓝牙设备的服务 uuid
- ms-access - MS 访问图表,日期来自其他表格
- react-native - 如何在 React Native 的 Text 组件中取消选择文本?
- python - Pandas 中两个不同数据框之间的布尔索引
- php - 在保持特定宽度或高度的同时旋转图像
- node.js - 使用 Mocha 和 Chai 为带有 response.send( ) 的函数编写测试用例
- python - 不同大小的焊炬张量相等
- angular - 可选择在 Angular 应用中加载 Firebase 模块
- ios - 向左/向右滑动单元格数组中的下一个图像 URL