我看遍了网络,仍然无法找到任何有效的工具。我知道这将是一件简单的事情,我只是没有想到,但我已经浪费了几个小时试图整理出来,仍然没有。所以我的代码如下。它只是填充datagridview,然后我希望用户能够通过在表单上的文本框中输入联系人姓名进行搜索,然后单击搜索按钮。帮助将不胜感激!Visual Studio 2008 C# - 我可以在dataviewgrid中搜索数据吗?
private void frmCustomers_Load(object sender, EventArgs e)
{
sqlDataAdapterCustomers.Fill(dataSetNWCustomers1.Customers);
}
private void btnContactSearch_Click(object sender, EventArgs e)
{
String contactName = txtContactSearch.Text;
if (txtContactSearch.TextLength > 0)
{
int r = customersBindingSource.Find("ContactName", contactName);
customersBindingSource.IndexOf(r);
}
}
所以我明白,你有一个绑定到SQL数据源的联系人的DataGridView。当用户输入搜索查询并单击提交时,您想过滤DataGridView以仅显示其搜索结果? – GregB 2011-03-24 00:50:40
是的,这是这个想法。 – 6TTW014 2011-03-24 00:55:54