在不更改DataGridView表的情况下搜索DataGridView

问题描述 投票:0回答:1

我有一个DataGridView,其中包含一些数据。我也有一个搜索TextBox,当它的文本更改时,我想在DataGridView中进行搜索,而不必changing原始DataGridView中的数据。

当客户写他的搜索行时,DataGridView将执行以下选项之一:

  1. 仅显示与搜索行匹配的行,
  2. 或将客户端跳到该行并突出显示(大于1)。

在StackOverflow上搜索时,我可以找到类似的情况,但无法在我的程序中应用其任何解决方案。

这是我到目前为止的代码:

private void search_TextChanged(object sender, EventArgs e)
{
    (dataGridView1.DataSource as DataTable).DefaultView.RowFilter = string.Format("name = '{0}'", search.Text);
}

但是它只显示一个空白的DataGridView,尽管我应该有一个结果。

c# winforms
1个回答
0
投票
然后在更新DataGridView时,我使用了此功能:

if (search.Text != "") { table = ConvertListToTable(Fund.funds,search.Text); } else { table = ConvertListToTable(Fund.funds,""); }

© www.soinside.com 2019 - 2024. All rights reserved.