How to bind Combobox column ItemsSource depend on other Combobox column in DataGrid ? RRS feed

  • Question

  • Hi all,

    I use EFW and domain service in my application. I have a datagrid that content of City and Town combobox columns as below.

          <ComboBox DisplayMemberPath="CityName" x:Name="ComboBoxCity"
                             SelectedValue="{Binding City_Id}"
                             SelectedValuePath="City_Id" ItemsSource="{Binding Data, Source={StaticResource cityDataSource}}">

          <ComboBox DisplayMemberPath="TownName"
                             SelectedValue="{Binding Town_Id}"
                             SelectedValuePath="Town_Id"    ItemsSource="??????">

    There is an association between City and Town entity relation on city_id. If I change City combobox selected Item then Town ItemsSource should change automatically in the same row. I try to cityDataSource.townDataSource and ElementName=ComboBoxCity, Path=Data.Towns, but It doesn't work.

    How can i do this. ? Please advise me. Thanks..

    • Moved by Jackie-Sun Friday, March 11, 2011 8:56 AM (From:ADO.NET Entity Framework and LINQ to Entities)
    Thursday, March 10, 2011 12:09 PM

All replies

  • Hi,

    Try to bind the Town Combo's ItemsSource to ComboBoxCity.SelectedItem.Towns by doing something like this: ItemsSource="{Binding SelectedItem.Towns, ElementName=ComboBoxCity}".

    If this doesn't work I suggest you to post the question at the WPF forum (http://social.msdn.microsoft.com/Forums/en-US/wpf/threads) since your problem is related to binding in WPF, and there probably is more persons there that can help you with this than here.

    Hope this helps!

    Thursday, March 10, 2011 9:23 PM
  • Thanks for your reply Rune. I try to your suggestion but It doesn't work. I post this question at the WPF forum. thanks again..

    Friday, March 11, 2011 7:14 AM