Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF DataGridTemplateColumn combobox updating all rows

I have this XAML that selects a value from a combobox that the ItemSource is a Enum. The tutorial I used is:

http://www.c-sharpcorner.com/uploadfile/dpatra/combobox-in-datagrid-in-wpf/

            <DataGrid x:Name="dgProductItem" 
                   ItemsSource="{Binding ProductVersion.ProductItems}"

            <DataGridTemplateColumn Header="Deployment Type" Width="120">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding DeploymentType}"></TextBlock>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
                <DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate>
                        <ComboBox ItemsSource="{Binding Source={StaticResource DeploymentTypeEnum}}"
                                  SelectedItem="{Binding DeploymentType}">

                        </ComboBox>
                    </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>

However when I change a value from one row, it will update all the rows. Does anyone know why this is?

Edit:

if I just change one row, it will only update that row, but when I go to change a different row, that row I just changed will also change the previous one..

Cheers

like image 994
user3428422 Avatar asked Mar 20 '23 19:03

user3428422


1 Answers

Apologies for the duplicates but after a few hours of guessing because there isn't enough material on the web for this kinda stuff, the solution is:

</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
    <DataTemplate>
        <ComboBox ItemsSource="{Binding Source={StaticResource DeploymentTypeEnum}}"
                  SelectedItem="{Binding DeploymentType}"
                  **IsSynchronizedWithCurrentItem="false**">
        </ComboBox>
    </DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>

IsSynchronizedWithCurrentItem - does what it says on the tin. However, when you select an item, the current one will disappear but at least it won't update all rows.

like image 175
user3428422 Avatar answered Apr 01 '23 02:04

user3428422