DataGridComboBoxColumn loses its content when selection changes

When I click on a cell in my DataGridComboBoxColumn, the ComboBox becomes visible and I can select the elements. When I selected the item visible from above, thatโ€™s fine. But when the aka ComboBox cell loses focus, because I click something else in the DataGrid, then in the cell I previously selected there is no more element / text.

How to save this selected / selected text?

thats my code:

<DataGridComboBoxColumn Width="*" Header="Monday" DisplayMemberPath="SchoolclassName" SelectedValueBinding="{Binding SchoolclassCodeMonday}" ItemsSource="{Binding Source={StaticResource ClassCodes}}"> <DataGridComboBoxColumn.ElementStyle> <Style TargetType="ComboBox"> <Setter Property="IsSynchronizedWithCurrentItem" Value="False" /> <Setter Property="ItemsSource" Value="{Binding Source={StaticResource ClassCodes}}" /> </Style> </DataGridComboBoxColumn.ElementStyle> <DataGridComboBoxColumn.EditingElementStyle> <Style TargetType="ComboBox"> <Setter Property="ItemsSource" Value="{Binding Source={StaticResource ClassCodes}}" /> <Setter Property="IsDropDownOpen" Value="True" /> </Style> </DataGridComboBoxColumn.EditingElementStyle> </DataGridComboBoxColumn> 

seems to be the solution to my problem: http://wpf.codeplex.com/Thread/View.aspx?ThreadId=46627 (scroll down), but I can not pass the solution to my problem. Because my installation of the model is completely different.

SchoolclassName is a row property in Schoolclass.cs SchoolclassCodeMonday is a row property in TimeTable.cs ClassCodes aka SchoolclassCodes is a property of type ObservableCollection | Schoolclass |

Does anyone know how to fix my binding?

+6
wpf selecteditem datagridcomboboxcolumn
source share
1 answer

I know that he probably is no longer needed, but perhaps this will help someone else. Your ComboBox should not update the binding when it changes? eg.

 SelectedValueBinding="{Binding SchoolclassCodeMonday}" 

:

 SelectedValueBinding="{Binding SchoolclassCodeMonday, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 

Also, make sure you activate a notification when a property is changed from the code of your observed collection.

+1
source share

All Articles