WPF DataGridTemplateColumn combobox updating all rows

妖精的绣舞 提交于 2019-12-22 09:19:53

问题


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:


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.



来源:https://stackoverflow.com/questions/23290946/wpf-datagridtemplatecolumn-combobox-updating-all-rows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!