WPF Reflections

Jan 31 2008   1:03PM GMT

Combobox – using simple properties

Mark Shurmer Profile: MarkWPF

To follow on from my previous post about Comboboxes (see binding combo boxes to objects), how do you bind to a simple int representation of a foreign key?

Lets say you have a Person object, with a member called Employee which is an int and refers to the Id on an Employee object.

When you want to bind to an Person object with an int you set:

  • SelectedValue – this points to the EmployeeId member (typically set to {Binding Path=EmployeeId})
  • SelectedValuePath – point this to the member of the Employee object that will match up to your EmployeeId member, typically this will be set to {Binding path=Id}
  • DisplayMemberPath – point this to the member of the Employee that displays something meaningful, like Name. This will then get displayed in the drop down.
  • ItemsSource – point this to the ObservableCollection that holds the list of Employees

This is all you need to do -)

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: