Magnus Ahlin

Magnus Ahlin

  • NA
  • 1
  • 1.5k

DataGrid rows bound to the same row.

Jun 15 2011 1:24 PM

Im using WPF4 and I have a datagrid bound to to a collection of instances of a plain class.

It works fine for most of the columns but one column bound to s string property is a template column with a combobox in it which is populated from a object dataprovider.

it works fine, however, when I add more than one row and select a different item all rows gets updated with that value. I can change the other columns without this happening.

Any ideas?

<DataTemplate x:Key="subIndexComboBoxCellTemplate" >
<ComboBox SelectedItem="{Binding Code, UpdateSourceTrigger=PropertyChanged}" Padding="0" Margin="0">
<ComboBox.ItemsSource>
<Binding>
<Binding.Source>
<StaticResource ResourceKey="indexCodes" />
</Binding.Source>
</Binding>
</ComboBox.ItemsSource>
</ComboBox>
</DataTemplate>

  <DataGrid ScrollViewer.CanContentScroll="True" ItemsSource="{Binding SubIndices}" Margin="5" CanUserAddRows="False" AutoGenerateColumns="False" >
    <DataGrid.Columns>
  <DataGridTemplateColumn Header="Sub Index Code" CellEditingTemplate="{StaticResource subIndexComboBoxCellTemplate}" CellTemplate="{StaticResource subIndexComboBoxCellTemplate}" />


Answers (3)