How to add a combobox item in a custom control combo box binded to a query?
-
Monday, July 18, 2011 3:12 AM
I have a combobox binded to a tags query and use the selected_tag as a parameter to filter the datagrid using the code below, the problem is I want to add an item "all" to the combobox because once I selected a tag i can't remove the datagrid's filter.
IContentItemProxy comboControl = this.FindControl("Selected_Tag");
comboControl.SetBinding(System.Windows.Controls.ComboBox.ItemsSourceProperty, "Screen.Tags", System.Windows.Data.BindingMode.OneWay);
comboControl.SetBinding(System.Windows.Controls.ComboBox.SelectedItemProperty, "Screen.Selected_Tag", System.Windows.Data.BindingMode.TwoWay);
All Replies
-
Monday, July 18, 2011 3:31 AM
Normally people try to do this in a query's PreProcessQuery method, & you can't do this, because you can't "add" records to a query, you can only retsrict the records that are provided in the "query" parameter.
If you created a custom RIA service & used that as your query's source, you might be able to achieve this, by appending an "all" record to the table's records "on the fly".
The way I handle this, is to always have a "zero" record in all of my "lookup" tables, that is a record with an id of "0". It takes a bit of fiddling with data initialisation scripts, because unfortunately you can't specify that a table's id start at 0, it always starts at 1.
I then manipulate that record as I'm displaying it, but again there's some mucking around involved with that as well. If all you ever want to use it for is "all", it's easy, just use "all" as the lookup text for the zero record, but I also sometimes want to use it for "select" as well, hence the mucking around. It's not such a problem until you want to display one combo with "all" & another with "select".
Another way I guess you could handle the situation s with a screen query that you populate yourself, rather than from a table query, like Tim's article, Add Non Existent Records Using AutoCompleteBox.
(plus ça change, plus c'est la même chose!)
- Marked As Answer by pimlong Tuesday, July 19, 2011 3:23 AM
-
Monday, July 18, 2011 3:41 AM
If you created a custom RIA service & used that as your query's source, you might be able to achieve this, by appending an "all" record to the table's records "on the fly".
(plus ça change, plus c'est la même chose!)
This is the option I would choose. WCF RIA Services are actually very easy to create. It does not take a lot of time and will provide a solid solution that will withstand changes.
-
Tuesday, July 19, 2011 2:08 AM
Hi Pimlong
I know I have the solution you are looking for, but as in other times, I propose an alternative, but are not bothering anyone, a combox combined with a button. Works for me. You tell if you're interested.
Jaime
-
Thursday, July 21, 2011 10:41 AM
Hi
The description for the suggestion of the previous post is in: Filtering Data in a datagrid With A combobox.
Jaime

