Presenting listbox's Items in Datagrid Combobox column C# WPF

28 views Asked by At

I need to create a listbox that takes input from the user and those items are presented in the datagridcombobox column dropdown menu and the selected value of the column is coming from a variable in C# code behind.

I am trying to do it but either I can show the dropdown values or the selected values. If I use selectedvalueBinding then I can show the selected values in column from the variable but then I get is an error for dropdown values that selectedvalue is not present in listbox.

If I don't use selectedvalueBinding, then column values are not visible.

<DataGridComboBoxColumn 
     Header="Selected Item" DisplayMemberPath="Name" 
     SelectedValueBinding="{Binding Name}" 
     SelectedValuePath="Name" Width="*">
    <DataGridComboBoxColumn.ElementStyle>
        <Style TargetType="ComboBox">
            <Setter Property="ItemsSource" Value="{Binding Name, Path= Customer}"/>
        </Style>
    </DataGridComboBoxColumn.ElementStyle>
    <DataGridComboBoxColumn.EditingElementStyle>
        <Style TargetType="ComboBox">
            <Setter Property="ItemsSource" Value="{Binding DataContext.ListBoxItems, RelativeSource={RelativeSource AncestorType=DataGrid}}"/>
        </Style>
    </DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
0

There are 0 answers