How can I filter my DataGrid items like MS Access filter works (just select by mouse some part of cell and press "Filter" button)?
I have ViewModel MyViewModel with 2 Commands (Filter and ClearFilter) and ObservableCollection I have Model with method GetItems(...);
in DataGrid CellEditEnding event I save selected path and column name:
_selectedColumn = e.Column; if (e.EditingElement is TextBox) _selectedText = (e.EditingElement as TextBox).SelectedText;
So I have 2 params: my T object's property name, on which it is necessary to sort, and filter value (both are typeof String).
How should I change the Model's method GetItems, what would it work. Method Model.GetItemws uses EntityFramework to query items from database. How can I apply to this query my filter and how I can build this query? Some dynamic LINQ/Expression
var items = EFQuery().**Where(myFilter)**.ToList();
Where and how should I create this myFilter?
You can write filter lambda like this:
.Where(x => x.GetType().GetProperty(AA).GetValue(x).ToString().Contains(BB))
Where AA is variable which contains selected column name
BB is a variable which contains a filter text.
Restriction: Your property AA must be the string or class which having overridden ToString Method