WPF Reflections

Jan 31 2008   1:03PM GMT

Combobox - using simple properties



Posted by: Mark Shurmer
WPF

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


You must be logged-in to post a comment. Log-in/Register