WPFToolkit DataGrid: Combobox column does not update selected bind value immediately

I am using the WPF Toolkit DataGrid and DataGridComboBoxColumn. Everything works well, except that when you change the selection in the combo box, the selected binding source is not immediately updated. This only happens when the combo box loses focus. Does anyone come across this issue and any suggestions?

Here is the xaml for the column:

<toolkit:DataGridComboBoxColumn Header="Column" SelectedValueBinding="{Binding Path=Params.ColumnName, UpdateSourceTrigger=PropertyChanged}" DisplayMemberPath="cName" SelectedValuePath="cName"> <toolkit:DataGridComboBoxColumn.ElementStyle> <Style TargetType="ComboBox"> <Setter Property="ItemsSource" Value="{Binding Info.Columns}" /> </Style> </toolkit:DataGridComboBoxColumn.ElementStyle> <toolkit:DataGridComboBoxColumn.EditingElementStyle> <Style TargetType="ComboBox"> <Setter Property="ItemsSource" Value="{Binding Info.Columns}" /> </Style> </toolkit:DataGridComboBoxColumn.EditingElementStyle> </toolkit:DataGridComboBoxColumn> 
+4
source share
2 answers

The problem is that the cell remains in edit mode until you leave the cell and the changes are not implemented. I posted more detailed information in AutoCommitComboBoxColumn

Solution: you need to create your own column type in order to override the default code behavior:

 public class AutoCommitComboBoxColumn : Microsoft.Windows.Controls.DataGridComboBoxColumn { protected override FrameworkElement GenerateEditingElement(Microsoft.Windows.Controls.DataGridCell cell, object dataItem) { var comboBox = (ComboBox)base.GenerateEditingElement(cell, dataItem); comboBox.SelectionChanged += ComboBox_SelectionChanged; return comboBox; } public void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { CommitCellEdit((FrameworkElement)sender); } } 
+3
source

UpdateSourceTrigger = PropertyChanged is critical here, it cannot do without it.

+10
source

Source: https://habr.com/ru/post/1310303/


All Articles