我想通过collectionView过滤我的数据表。
我试过这段代码:
private MaterialTableAdapter materialTableAdapter = new MaterialTableAdapter();
private CollectionView viewSource;
public PgMaterials()
{
InitializeComponent();
IMDataSet.MaterialDataTable mdt = materialTableAdapter.GetData();
this.mainGrd.DataContext = mdt;
viewSource = (CollectionView)CollectionViewSource.GetDefaultView(mdt);
viewSource.MoveCurrentToFirst();
viewSource.Filter = FilterResults;
}
private bool FilterResults(object obj)
{
//(Ignore spaces).
string name = (obj as IMDataSet.MaterialRow).Name.Replace(" ", "");
string searchedString = textBox.Text.Replace(" ", "");
return (name.Contains(searchedString));
}
private void textBox_TextChanged(object sender, TextChangedEventArgs e)
{
viewSource.Refresh();
}
但是当我运行应用程序时,会抛出以下异常:
不支持指定的方法。