WPF DataGrid - new cell value after editing

On my system, I need to capture and send the old and new cell edit value. I read that you can do this by checking the EditingElement of the DataGridCellEditEndingEventArgs event as follows:

_dataGrid.CellEditEnding += (sender, e) => { var editedTextbox = e.EditingElement as TextBox; if (editedTextbox != null) MessageBox.Show("Value after edit: " + editedTextbox.Text); } 

In my case, the data is a dictionary, so EditingElement is a ContentPresenter

 var editedTextbox = e.EditingElement as ContentPresenter; if (editedTextbox != null) MessageBox.Show("Value after edit: " + editedTextbox.Content); 

and the content is the original, not the new edited value.

How can I make this work:

 _dataGrid.SomeEvent(sender, e)->{ SendValues(e.oldCellValue, e.newCellValue); } 
+7
c # wpf datagrid
source share
2 answers

I realized that my string data objects inherit from IEditableObject. I am processing the updated value in the EndEdit () interface method

+5
source share

Try connecting to NotifyOnTargetUpdated - hope this is what you are looking for

 <DataGrid Name="datagrid" AutoGenerateColumns="False" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling"> <DataGrid.Columns> <DataGridTextColumn Header="Title" Binding="{Binding Path=Name,NotifyOnTargetUpdated=True}" Width="300"> <DataGridTextColumn.EditingElementStyle> <Style TargetType="{x:Type TextBox}"> <EventSetter Event="LostFocus" Handler="Qty_LostFocus" /> <EventSetter Event="TextChanged" Handler="TextBox_TextChanged" /> <EventSetter Event="Binding.TargetUpdated" Handler="DataGridTextColumn_TargetUpdated"></EventSetter> </Style> </DataGridTextColumn.EditingElementStyle> </DataGridTextColumn> </DataGrid.Columns> </DataGrid> 
+2
source share

All Articles