DataGridComboBoxColumn not updating model WPF

I'm using Datagrid in WPF and DataGridComboBoxColumn. Please find the code below:

<DataGrid>...                 

    <DataGridComboBoxColumn Header="Category" Width="200"                                        
                                    SelectedValueBinding="{Binding SelectedCategory, UpdateSourceTrigger=PropertyChanged}"
                                    DisplayMemberPath="CategoryName"
                                    SelectedValuePath="CategoryID">
        <DataGridComboBoxColumn.ElementStyle>
            <Style TargetType="ComboBox">
                <Setter Property="ItemsSource" Value="{Binding CategoriesList}"></Setter>
            </Style>
        </DataGridComboBoxColumn.ElementStyle>
        <DataGridComboBoxColumn.EditingElementStyle>
            <Style TargetType="ComboBox">
                <Setter Property="ItemsSource" Value="{Binding CategoriesList}"></Setter>
            </Style>                        
        </DataGridComboBoxColumn.EditingElementStyle>
   </DataGridComboBoxColumn>

The model is as follows:

public CategoryModel SelectedCategory { get; set; }
public ObservableCollection<CategoryModel> CategoriesList
{
    get;
    set;
}

Now when ever I change the selection in combobox it shows a red border, unable to commit the changes to the source.

Upvotes: 3

Views: 1451

Answers (1)

Florian Schmidinger
Florian Schmidinger

Reputation: 4692

This is wrong:

<DataGridComboBoxColumn Header="Category" Width="200"                                        
                                SelectedValueBinding="{Binding SelectedCategory, UpdateSourceTrigger=PropertyChanged}"
                                DisplayMemberPath="CategoryName">

remove the SelectedValuePath or you get a type missmatch. I doubt you need the UpdateSourceTrigger either... Try to ommit.

Upvotes: 1

Related Questions