WPF DataGridTemplateColumn combobox updating all r

2019-05-10 16:33发布

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

1条回答
再贱就再见
2楼-- · 2019-05-10 17:16

Aplogises for the duplicates but after a few hours of guessing because there isnt 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 wont update all rows.

查看更多
登录 后发表回答