4

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

user3428422
  • 4,300
  • 12
  • 55
  • 119
  • 1
    -1 For duplicating questions... even worse that you're duplicating your *own* question. How many questions do you want to ask about the same problem? On this site, we prefer users to edit their questions to provide more information, not ask the same question repeatedly. – Sheridan Apr 25 '14 at 10:54
  • However, the answer to this question is because your `DeploymentType` is almost certainly singular, but you are using it for every row in the `DataGrid`. Your `enum` property needs to be in the class that each item in the `DataGrid` belongs to. – Sheridan Apr 25 '14 at 10:55
  • I agree, its the same question but its totally different code, and editing a previous question would be pointless as will be too far down in the list. So therefore it would be an utter waste of time – user3428422 Apr 25 '14 at 10:56
  • Thanks, but the enum property is in my model ProductVersion.ProductItems class – user3428422 Apr 25 '14 at 10:57
  • It's *not* totally different code... that's how I knew it was the same question... because the code is so similar. And edits refresh the position of questions so it would have the same effect. Please read through the [Help Center](http://stackoverflow.com/help) to see what you should and shouldn't do on this website. – Sheridan Apr 25 '14 at 10:59
  • The answer is still the same... somewhere in your code, you are using one `enum` value that is shared between all of the items... you just need to find it. – Sheridan Apr 25 '14 at 11:00
  • Ok I apologise, I didnt know it refreshed the position. I wont create same question again. well, this is what is happening, if I just change one row, it will only update one row, but when I go to change a different row, the row I just changed will also change the previous if you get me? so basically its like its doing it on selected row previous – user3428422 Apr 25 '14 at 11:03
  • Where is your `DeploymentType` property defined?... I'm guessing that's not in your item class. – Sheridan Apr 25 '14 at 11:04
  • The enum itself is in its own class with a diferrent namespace. But the property DeploymentType is defined in the ProductItem model class. So basically I can get the Deployment type property from the Itemsource of the Datagrid, thats where I think the problem lies – user3428422 Apr 25 '14 at 11:06
  • 1
    Where is the duplicate? I could use the solution to this problem. – Eric Jun 29 '16 at 14:49

1 Answers1

9

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.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
user3428422
  • 4,300
  • 12
  • 55
  • 119