【发布时间】:2018-04-13 08:50:34
【问题描述】:
每次用户在文本框中键入我运行新查询时,我都有用于在列表视图中搜索的列表视图和文本框,有没有更好的方法来做到这一点?无需仅从 itemsources 从数据库运行查询?
private void txtEditSearch_TextChanged(object sender, TextChangedEventArgs e)
{
if (txtEditSearch.Text != string.Empty)
{
var query = GetAllSchoolsAsync(txtEditSearch.Text);
query.Wait();
List<DataClass.Tables.School> data = query.Result;
if (data.Any())
dgv.ItemsSource = data;
}
else
getSchool();
}
我需要这样的东西:
var basedata = dgv.Itemsource;
dgv.ItemSource = basedata.where(x=>x.Name == txtEditSearch.Text).Select(x=>x);
【问题讨论】:
-
为什么不从数据库中查询所有记录一次?然后你在这个源上执行你的过滤器。