I have a dictionary which I want to allow the keys to be selected in a combobox but also display the value without having to create another column.
For instance, if my dictionary consists of 3 items for now
Dictionary<string, double> test = new Dictionary<string, double>();
//KEY , VALUE
//"Item1" , 4.0
//"Item2" , 4.5
//"Item3" , 5.0
I want the combobox pulldown list to display the available selections showing BOTH key and value
[Item1, 4.0]
[Item2, 4.5]
[Item3, 5.0]
and say if [Item2, 4.5] is selected then only the key is displayed in the combobox as the current selection, in this case the following would display after selection…
Item2
I’ve tried the following but this shows [key,value] in both the combobox selection list and after selection
comboboxColumn2.SelectedValuePath= "Key";
comboboxColumn2.ItemsSource = test;
I’ve also tried using combinations with comboboxColumn2.DisplayMemberPath= "Value"; but cannot get it formatted as I would like.
Can anyone say if it’s possible and what the correct syntax is?
EDIT:
The combobox are actually ComboboxColumns so there are only 2 events available which don’t appear very useful
<DataGrid.Columns>
<DataGridComboBoxColumn Header="Department Id" x:Name="comboboxColumn1"
SelectedValueBinding="{Binding Department Id}" />
<DataGridComboBoxColumn Header="Department Id" x:Name="comboboxColumn2"
SelectedValueBinding="{Binding Department Name}"/>
</DataGrid.Columns>
If you want to do this on code behind here it is :
I just created an formatedSource and then changed the displayMemberPath according to your description.
Hope it helps