I'm using two RadComboBox controls in my Silverlight app, one for countries and one for counties. I want the counties list to change depending on the selected country. (I'm using RIA Services for the data back end)
I can achieve this by using the following code:
private void PropertyDetailsEditCountriesCombo_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
Country selectedCountry = CountriesCombo.SelectedItem as Country;
CountiesCombo.ItemsSource = db.Counties.Where(c => c.country_id == selectedCountry.id).OrderBy(c => c.countyName);
CountiesCombo.DataContext = currentRecord;
CountiesCombo.SelectedIndex = -1;
My problem arises when the combo's are already bound to a record, e.g. Country = Ireland, County = Dublin, when the country is changed to England the counties change as desired and no record is selected, but the original record for the county (i.e Dublin) is still in the list along with the counties for England. I have tried to use the items.clear method but I get an error to say this is not possible because it's a read only collection.
Can you tell me how I can remove the previously selected record?
Also, can you suggest a way to stop the code in the SelectionChanged event from firing when the Countries combo is initially bound to a record?