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);
答案 0 :(得分:1)
如果列表视图填充了数据,您可以过滤该数据,就像搜索一样,只显示您要求的数据。以下是我从中了解到的链接:
http://www.wpf-tutorial.com/listview-control/listview-filtering/
答案 1 :(得分:0)
我建议您实现此目的的最佳方法是从此集合创建初始未过滤的集合和过滤器。
创建一个私有字段来存储初始的学校项目:
private List<DataClass.Tables.School> _initialCollection;
使用构造函数中未过滤的项填充它:
public MyView()
{
var query = GetAllSchoolsAsync();
query.Wait();
_initialCollection = query.Result;
}
在TextChanged事件处理程序中,您可以将过滤添加到ListView的ItemSource:
private void txtEditSearch_TextChanged(object sender, TextChangedEventArgs e)
{
dgv.ItemSource = _initialCollection.Where(x=>x.Name == txtEditSearch.Text).Select(x=>x);
}