Reputation: 21
I have a datagrid
with a template column and a combobox
inside it. I also have another combobox
which is not inside the datagrid
:
<DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True"
ItemsSource="{Binding Source={StaticResource asientoDetallesAsientosViewSource}}"
Name="detallesAsientosDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" >
<DataGrid.Columns>
<DataGridTemplateColumn Header="Cuenta">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox Grid.Column="1" Grid.Row="0"
Name="combo1"
ItemsSource="{Binding Source={StaticResource cuentaListaViewSource}}"
SelectedValuePath="Numero"
DisplayMemberPath="Nombre"
SelectedValue="{Binding ElementName=detallesAsientosDataGrid, Path=SelectedItem.Numero}">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Numero}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<ComboBox Name="combo2"
ItemsSource="{Binding Source={StaticResource cuentaListaViewSource}}"
SelectedValuePath="Numero"
DisplayMemberPath="Nombre"
SelectedValue="{Binding ElementName=detallesAsientosDataGrid,
Path=SelectedItem.Numero}"
VerticalAlignment="Center" Width="120">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
Now the strange thing and the problem is that in this case the combo1
inside the datagrid
, when in edit mode, shows correctly the selected row value BUT if I delete the combo2
the combo1
stops working and doesn't anymore show the selected row value but instead the first value of the combobox
list.
Why does it happen? The combo2
is exactly the same combobox
as the combo1
.
Upvotes: 1
Views: 1369
Reputation: 45096
They both bind to the same SelectedValue. If you delete (edit) the SelectedValue then the selected value is no longer in the ItemsSource. If you select (not edit) a value from the pull down does it work?
Upvotes: 1