我有一个DataGridView
,其中包含一些数据。我也有一个搜索TextBox
,当它的文本更改时,我想在DataGridView
中进行搜索,而不必changing原始DataGridView
中的数据。
当客户写他的搜索行时,DataGridView
将执行以下选项之一:
在StackOverflow上搜索时,我可以找到类似的情况,但无法在我的程序中应用其任何解决方案。
这是我到目前为止的代码:
private void search_TextChanged(object sender, EventArgs e)
{
(dataGridView1.DataSource as DataTable).DefaultView.RowFilter = string.Format("name = '{0}'", search.Text);
}
但是它只显示一个空白的DataGridView
,尽管我应该有一个结果。
if (search.Text != "")
{
table = ConvertListToTable(Fund.funds,search.Text);
}
else
{
table = ConvertListToTable(Fund.funds,"");
}