WPF Datagrid Row Editing "ENDED" event WPF Datagrid Row Editing "ENDED" event wpf wpf

WPF Datagrid Row Editing "ENDED" event


    private void dgrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)    {        if (this.dgrid.SelectedItem != null)        {            (sender as DataGrid).RowEditEnding -=dgrid_RowEditEnding;            (sender as DataGrid).CommitEdit();            (sender as DataGrid).Items.Refresh();            (sender as DataGrid).RowEditEnding += dgrid_RowEditEnding;        }        else Return;       //then check if the newly added row is duplicated    }


You can use UpdateSourceTrigger=PropertyChanged on the binding of the property member for the datagrid. This will ensure that when CellEditEnding is fired the update has already been reflected in the observable collection. see this post https://stackoverflow.com/a/27239243/9285072


I found an answer to your question usingVS2010

condition if (e.EditAction == DataGridEditAction.Commit) in the RowEditEnding will fulfill ur requirement

Please see the below code.

private void dataGrid1_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e){    if (e.EditAction == DataGridEditAction.Commit)    {        MessageBox.Show("asd");    }}

This is the Xaml Behind.

<DataGrid AutoGenerateColumns="False" CanUserAddRows="True" Height="241"     RowEditEnding="dataGrid1_RowEditEnding" HorizontalAlignment="Left"     Name="dataGrid1" VerticalAlignment="Top" Width="573" >    <DataGrid.Columns>        <DataGridTextColumn Header="name" Binding="{Binding id}"             Width="300">        </DataGridTextColumn>    </DataGrid.Columns></DataGrid>