0
votes

I am trying to bind my list VC_Functions which I have as a StaticResource of my Combobox. The value selected should be two-way binded to a parameter function_tid of the ItemsSource of the Datagrid that the ComboBox is in. VC_Functions is defined as list of vc_double.

So in essence, I am trying to populate my ComboBox from a list with two parameters, name and desc. name should be the value shown in the dropdown list and then this should be binded to the value of function_tid in the ItemSource of the Datagrid.

I would imagine it is a combination of SelectedValuePath, SelectedValue, etc... However I am not so familiar with WPF.

This is what my XAML looks like currently:

<DataGridTemplateColumn Header="Function TID" Width="80*">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding function_tid}"/>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                                <DataGridTemplateColumn.CellEditingTemplate>
                                    <DataTemplate>
                                        <ComboBox Height="22"
                                      IsEditable="True"
                                      IsTextSearchEnabled="True"
                                      ItemsSource="{StaticResource VC_Functions}"
                                      SelectedItem="{Binding name}"
                                      DisplayMemberPath="name">
                                            <ComboBox.ItemContainerStyle>
                                                <Style>
                                                    <Setter Property="Control.ToolTip" Value="{Binding desc}"/>
                                                </Style>
                                            </ComboBox.ItemContainerStyle>
                                        </ComboBox>
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellEditingTemplate>
                            </DataGridTemplateColumn>

VC_Functions is composed of vc_double:

public class vc_double
    {
        public string desc { get; set; }
        public string name { get; set; }

        public vc_double() { }
    }

Datagrid Itemsource:

public class DataGridRows
        {
            public string function_tid { get; set; }
            ... etc
        }

One thing I would like to clarify is that the ComboBox populates from the VC_Functions as intended with the correct values, but whenever one of them is selected a binding error occurs and does not bind to function_tid

1

1 Answers

0
votes

So I actually found the solution and it was relatively simple.

I replaced the line

SelectedItem="{Binding name}"

with the lines

SelectedValue="{Binding function_tid}"
SelectedValuePath="name"