Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 857405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:23:38+00:00 2026-05-15T08:23:38+00:00

EDIT: The issue underneath is fixed, GO TO EDIT2 in this post. I have

  • 0

EDIT: The issue underneath is fixed, GO TO EDIT2 in this post.

I have an Organisation entity and a Region entity. An object of type Organisation can have one or more Region objects connected to it, thus I have a foreign key in my Region entity to the Organisation Entity. The Organisation and Region objects are pulled from my database using WCF RIA and entity framework. I want to put the Organisation objects in one ComboBox and the Region objects in another ComboBox, and when selecting an organsation having the ComboBox for Region objects automatically only showing regions that are connected to the selected organisation. Should be pretty basic, but the way I’ve designed it right now it doesnt work at all.

So, any hint to how I can achive this? A simple simple codeexample is much appreciated!
(I’m using SL4,WCF RIA MVVM)

EDIT2 EDIT2 EDIT2 EDIT2 EDIT2 EDIT2 EDIT2 EDIT2 EDIT2 EDIT2 EDIT2 EDIT2:

Using Venomo’s ElemntBinding answer this is working great for me now when I want to add a new object to my collection, and I’m just pulling the avaible countries and connected regions and then type a site in a textbox…So I get my combination of Organisation, region and site in my database 🙂

Now, I’ve got a new problem when I want to EDIT a site in my collection. In EDIT mode, I want the two dropdowns to be preselected and disabled (BusinessRule is that I can edit the sitename, not which organisation og region it’s connected to). So by setting the SelectedIndex property on Organisation combobox I get my organisation selected, but when doing the same on the Regions combobox it fails with an Object Reference error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:23:38+00:00Added an answer on May 15, 2026 at 8:23 am

    You can achieve this with some clever ElementBindings.

    Basic example:

    Let’s say we have a simple class like this:

    public class Country
    {
        public string Name { get; set; }
    
        public IEnumerable<string> Regions { get; set; }
    }
    

    Then, we’ll have two ComboBoxes: one for choosing a country and another for choosing a region in that country. The second one should update itself when the value of the first one changes.

    Okay, first we have to tell Silverlight how to display a Country. For complex scenarios we could use a DataTemplate for that, but for now, we will only need the DisplayMemberPath property of the ComboBox class.

    <ComboBox x:Name="cbCountries" DisplayMemberPath="Name"/>
    

    So, we create a simple collection of these objects in the code behind:

    var countries = new List<Country>()
    {
        new Country
        {
            Name = "USA",
            Regions = new List<string>
            {
                "Texas", "New York", "Florida", ...
            },
        },
        new Country
        {
            Name = "UK",
            Regions = new List<string>
            {
                "Scotland", "Wales", "England", ...
            },
        },
        ...
    };
    

    I know that those are not all of the regions in the example countries, but this is a Silverlight example and not a geographical lesson.

    Now, we have to set the ItemsSource of the ComboBox to this collection.

    cbCountries.ItemsSource = countries;
    

    Both of these can be in the constructor in the code-behind.
    Okay, now back to XAML!

    We’ll need another ComboBox and a way for telling it to get its items from the other collection dynamically.
    Binding its ItemsSource to the other ComboBox‘s selected item is just the most obvious way to achieve that.

    <ComboBox x:Name="cbRegion" ItemsSource="{Binding ElementName=cbCountries, Path=SelectedItem.Regions}"/>
    

    This should do the trick quite simply.

    If you use MVVM:

    You can bind to the ItemsSource of the first ComboBox from the ViewModel. The rest remains the same.
    To tell what the selected values are to the ViewModel, use Two-way bindings on the SelectedItem property of both ComboBoxes and bind that to whatever property you have for it in the ViewModel.

    If your collection can change dynamically:

    If the list of the countries (or whatever it is that you want to use this for) can change during runtime, it is best if you implement INotifyPropertyChanged for the Country class and for the regions, use ObservableCollection<>.
    If it doesn’t need to change during runtime, no need to bother with these.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a Cake PHP novice. I want to edit the table Issue. This
(EDIT: This question is now outdated for my particular issue, as Google Code supports
Edit: Entity Framework seems to be the issue, discussed further in question Entity Framework
//EDIT My issue was related to something else, I thought the implementation was incorrect
EDIT: I have added Slug column to address performance issues on specific record selection.
Edit: This question was written in 2008, which was like 3 internet ages ago.
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
EDIT: This question is more about language engineering than C++ itself. I used C++
I have the following element on my form: <li> <label class=fixed for=Interests>Program genre interests:</label>
EDIT ive got it almost, having and error message now that it can't find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.