I have always struggled with those comboBox properties
- DisplayMemberPath
- SelectedValue
- SelectedValuePath
I am building a master detail form .
- ComboBox filled with Customers
- User Selects a Customer in Combo
- All the textBoxes EG Fills correctly
The problem I am having I have made it work but I don't understand those properties and the differences.
Is there a noddy example explaining what they do?
Best Answer
I think we can understand this better with an example. See this class:
and the following xaml:
DisplayMemberPath
points to theName
property, so the value displayed in theComboBox
and theEmployee
entries contained in the drop down list, will be theName
property of theEmployee
object.To understand the other two, you should first understand
SelectedItem
.SelectedItem
will return the currently selectedEmployee
object from theComboBox
. You can also assignSelectedItem
with anEmployee
object to set the current selection in theComboBox
.SelectedValuePath
points toId
, which means you can get theId
of currently selectedEmployee
by usingSelectedValue
. You can also set the currently selectedEmployee
in theComboBox
by setting theSelectedValue
to anId
(which we assume will be present in theEmployees
list).