【发布时间】:2015-10-09 11:22:57
【问题描述】:
当用户在搜索框中输入内容时,我想过滤我的 DataGrid。我通过以下方式将我的数据绑定到我的 DataGrid;
在我的数据访问器中;
public DataTable FillDataGrid()
{
string constr = ConfigurationManager.ConnectionStrings["dbfString"].ConnectionString;
using (OleDbConnection dbfCon = new OleDbConnection(constr))
{
try
{
dbfCon.Open();
DataTable dTable = new DataTable();
string dbfQuery = "SELECT em_pplid, em_name, em_netname, em_init, em_dept FROM employs WHERE em_netname NOT LIKE ''";
OleDbCommand MyQuery = new OleDbCommand(dbfQuery, dbfCon);
OleDbDataAdapter DA = new OleDbDataAdapter(MyQuery);
DA.Fill(dTable);
return dTable;
}
catch (OleDbException)
{
throw;
}
}
}
在我看来;
private void FillDataGrid(object sender, RoutedEventArgs e)
{
DataAccessor da = new DataAccessor();
DataTable dt = da.FillDataGrid();
dataGrid.ItemsSource = dt.AsDataView();
}
在我看来,当我知道如何正确过滤 DataGrid 时,我目前已经准备好成为搜索功能;
private void SearchGrid(object sender, TextChangedEventArgs e)
{
if (nNameRad.IsChecked == true)
{
MessageBox.Show("Hello!");
}
}
我在网上搜索了很多看似过时的过滤DataGrid的方法。如何在我的程序中执行此操作?
【问题讨论】: