I can't seem to find a way to do this. I create a datagrid whose datacontext is initially filled with rows from a table. I have implemented a search functionality that will return some rows based on a condition. Suppose I want to display
only those rows, how do I destroy the initially created datacontext and add the newly filtered collection?
I naively started doing it like this:
IEnumerable<MyType> rows = datagrid.Items.Cast<MyType>();
IEnumerable<MyType> filteredRows = rows.Where(row => row.someCondition == true);
how do I now make my datagrid display only the filteredRows? Just doing:
datagrid.DataContext = null;
datagrid.DataContext = filteredRows;
doesn't work (it even smells stupid for some reason).
I also need to do the reverse (once I get this working). Some buttonclick should allow the user to "clear" the search results and re-plug the DataContext back to "rows" (in the above snippet).
What am I missing?