Sukaskha

Sukaskha

  • NA
  • 113
  • 20.6k

WPF Combobox linking issue

Mar 30 2014 11:43 PM
I have 2 comboboxes and based on selection in 1st one, I want to populate 2nd one. How can I do this with two classes Country and City?

Answers (3)

0
Shweta Lodha

Shweta Lodha

  • 20
  • 48.5k
  • 4.2m
Mar 30 2014 11:52 PM
You can take below approach:
First create Country class that would contain country related information and all available city values in a collection. Somewhere in your code, instantiate a collection of the country and the corresponding cities.

In XAML, bind the ItemSource property of the combobox to that property. For 2nd combobox, bind it's ItemSource property to the list of cities from the SelectedItem of the first combobox.

Hope it will resolve your linking issue.
Accepted Answer
0
Shweta Lodha

Shweta Lodha

  • 20
  • 48.5k
  • 4.2m
Mar 30 2014 11:57 PM
Let me know, in case if you get stuck somewhere.
0
Sukaskha

Sukaskha

  • 0
  • 113
  • 20.6k
Mar 30 2014 11:57 PM
Shweta Lodha,
I'll give a try to this approach. Thanks for your suggestion.