Hi all,
I have the following situation. I am using a DataGrid to display a list of Boxes. Each Box has a ProductID property. I also have a list of Products, each of which has an ID and a Name.
I want to 1) display a product Name instead of the ProductID, and 2) allow the user to select a Product from a ComboBox in the CellEditor, and change Box.ProductID accordingly.
So far, I've been able to do #1 by using DisplayMemberBindingInfo with a Converter that turns ProductIDs into product names.
However, I'm stumped on #2. I've tried putting this in the cell editor template:
<ComboBox IsEditable="True" IsTextSearchEnabled="True" DisplayMemberPath="Name"
ItemsSource="{Binding Client.Products, Source={x:Static local:App.Instance}}"
SelectedValue="{Binding ProductID}"
SelectedValuePath="ID"/>
but it won't work, I think because at this point the source of the Binding of SelectedValue is not a Box, but rather a product name. So I've changed it to:
<ComboBox IsEditable="True" IsTextSearchEnabled="True" DisplayMemberPath="Name"
ItemsSource="{Binding Client.Products, Source={x:Static local:App.Instance}}"
SelectedValue="{xcdg:CellEditorBinding}"
SelectedValuePath="Name"/>
This results in the ConvertBack method of my Converter getting called with the selected product name, which won't work either (as I can't map back from product names to product IDs).
I realised that using DisplayMemberBindingInfo with a Converter is probably not the right way to do this, as it means that in the CellEditor I'm stuck with a product name. But I can't figure out how to do it otherwise. Help?