We're using a XamDataGrid to display the first 100 rows from a database query, and when a user enters a new grid filter we catch it and include it in the query, so they will still see at least 100 rows, instead of just filtering the items in view. This works fine.
What I'd like to do is add to the filter cell dropdown any items that aren't already represented by one of the grid's rows. I have a list of all values for a given column, and I'm handling the RecordFilterDropDownPopulating event to try and add those items to the e.DropDownItems collection.
The problem I'm having is that this is a collection of FilterDropDownItems, and in the constructor you have to specify a condition, special operand, or command. I know that the object has a flag called IsCellValue, and I'm guessing that's what I actually need to be true in order for my new FilterDropDownItems to work properly. Is there any way to create a FilterDropDownItem that behaves like the automatically added cell value items?
Hello John,
For an example of how to provide your own filter items to the drop down list please see the following article: http://help.infragistics.com/doc/WPF/2013.2/CLR4.0/?page=InfragisticsWPF4.DataPresenter.v13.2~Infragistics.Windows.DataPresenter.DataPresenterBase~RecordFilterDropDownPopulating_EV.html
As you can see, you have to provide a ComparisonCondition to the FilterDropDownItem constructor. There is no way at this time that would allow you to add a filter item without providing one of the arguments you specified (condition, operand or command). Now I presume that your issue with this is that you can't find where to get the ComparisonOperator that the ComparisonCondition needs. While there is no property that you can use for this, it's still possible to grab the current operator. For this I created a dictionary where the key and value are Field and ComboBox. I then created a style targeting FilterCellValuePresenter and handled the Loaded event. Inside the Loaded event I searched the visual tree for the ComboBox responsible for holding the different operators. I then stored the ComboBox inside the dictionary so I could reference it later in the RecordFilterDropDownOpening event. I've attached a sample that demonstrates this.
Keep in mind that this code will only work when using the basic record filtering. If you are using excel style filtering, the combobox code will not work. You will have to provide a ComparisonCondition with a pre-chosen operator.
Thanks for the response. Unfortunately this suggestion wasn't exactly what I needed, but I did come up with a viable solution. In the original code, adding a new FilterDropDownItem with a comparison condition using the Equals operator and a filter value of XYZ would result in a filter that worked like (cell = "= 'XYZ'") instead of (cell = 'XYZ'). This might be due to other changes/hacks we've made, but I couldn't get around this issue unless I handled the RecordFilterChanged event, looked for CellValuePresenter value starting with "= \'" and then replaced the filter value and text.
I now avoid having to do this step by creating a new class that inherits from FilterDropDownItem that has a parameter IsCellValue set to true at all times, and it sets the Value property to a string in the constructor. I know this isn't considered good practice, but I've been testing this all morning and it seems to be working well, so I'll compromise this time.
Something else I noticed though, I'm adding these new FilterDropDownItems in the RecordFilterPopulating event. It seems like this is only called once, the first time the dropdown is opened. I can handle the RecordFilterDropDownOpening event to add subsequent items, but is there another point where I can modify the collection of DropDownItems? I ask because in RecordFilterDropDownOpening it's an ObservableCollection, so the cost of addition operations is pretty high and there's no bulk add/remove methods.
Thanks again.