This is a migrated thread and some comments may be shown as answers.

Cascading Combobox - Item remains in list

1 Answer 43 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mark Shortt
Top achievements
Rank 1
Mark Shortt asked on 28 Jul 2011, 12:31 PM
Hi

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?

Thanks

Mark


1 Answer, 1 is accepted

Sort by
0
Konstantina
Telerik team
answered on 03 Aug 2011, 09:16 AM
Hi Mark,

I can suggest you to create a SelectedItem property and in its setter to assign the ItemsSource of the second ComboBox. Please find attached a sample project in which this is illustrated.

Hope this helps.

Kind regards,
Konstantina
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
Tags
ComboBox
Asked by
Mark Shortt
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Share this question
or