Cascading Combobox - Item remains in list

2 posts, 0 answers
  1. Mark Shortt
    Mark Shortt avatar
    22 posts
    Member since:
    Jan 2010

    Posted 28 Jul 2011 Link to this post

    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


  2. Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 03 Aug 2011 Link to this post

    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 >>
  3. DevCraft banner
Back to Top