I'd like to share a useful sample demonstrating XamComboEditors used as cascading filters in a XamGrid in Silverlight 4. The sample was created for a customer by our Developer Support team (kudos primarily to Jason D). The sample is in VB.NET as per the customer's specs, so I hope to have a C# version at a later date.
The sample uses RIA services to provide server-side data access; and in this case the data is coming from a code class in the web project itself, not from an external source, so you should be able to run this sample stand-alone. To do this, the DomainService class returns IQueryable objects based on the ObservableCollections provided by the Data Model.
The XamGrid has related Country, State, and City columns. Selecting a Country causes the State drop-down items to be filtered by Country, and so on.
I hope this sample is a useful guide. Again, I hope to have a C# version soon. Please feel free to post any comments, questions and improvements.
Thanks Francis that worked great. I thought i had already tried that step. Can you please show me the next step which is to filter the list of counties by the state id? Since I'm not using RIA services and the state and counties lists will be static lists persisted in the client side session, i will need a different technique than the one you demonstrated. I know I can query the counties something like this:
static
public IEnumerable<CountyTest> GetCountiesByStateId(int id)
{
var countiesByState =
from county in _list
where county.Cnt_St_Id == (int)id
select county;
return countiesByState;
}
But I'm not sure how to get this list into the county xamcomboeditor.
George,
Thanks for the sample. The stateComboBindingToIntegerConverter is currently returning an integer, while the SelectedItem of the XamComboEditor is expecting a StateTest object.
You can modify your return statement to be this:
return GetStateTestByID(inVal);
rather than this:
return GetStateTestByID(inVal).St_Id;
...and you should see the behavior you expect.
Please let me know if I can be of further assistance.
Francis
Here’s an updated copy of the project where the State combo is now mostly working. I’m starting to understand the converters better and realized I needed to create a 2nd converter for this combo. One to convert to text for the Text Block and one to convert to int for the combo. Its now writing to the business object, but when I click in a State cell to make the combo show it’s dropdown list, nothing is selected in the list (as it does in your sample). So this is my next challenge before moving on to making the State combo filter the County Combo.
Fyi: I named my state class “StateTest” and the county class “CountyTest” so their names would not conflict with your classes in DataUtil.cs which I was using as reference (ugly names… I know).
Thanks for your help in this!
I'll create a private support case with you for better tracking/notification and will also post the resolution here.
Thanks,
Please use this sample project as its a little further along now.
Thanks.