Share via

What Event Minics DataGrid.RowEditEnded

RogerSchlueter-7899 1,671 Reputation points
2026-03-26T05:43:50.72+00:00

I have a DataGrid bound to a DataTable. When the user finishes editing a row, I want to send that edited row back to a database but there is no RowEditEnded event. Is there any equivalent technique to know when a row has been sent to the backing DataTable and is thus ready to send to the database?

Developer technologies | Windows Presentation Foundation
0 comments No comments

Answer accepted by question author
  1. Susmitha T (INFOSYS LIMITED) 2,690 Reputation points Microsoft External Staff
    2026-03-26T12:25:25.4366667+00:00

    Thank you for reaching out!

     

    In WPF DataGrid, there isn't a direct RowEditEnded event. However, you can achieve the same outcome using the following recommended approaches:

    1.Using RowEditEnding event (UI-Level): This event is triggered when the user finishes editing a row. Since the commit may not be fully applied at the exact moment, recommend deferring your logic slightly using the dispatcher to ensure the changes are committed before processing.

    2.Using DataTable.RowChanged event (Recommended): Since your DataGrid is bound to a DataTable, the most reliable approach is to handle the RowChanged event. This event fires after the data have been committed to the DataTable, making it a safe point to send the updated roe to your database,

     
    Recommendation: Suggested using the RowChanged event for a more robust and reliable solution.

     

    Let me know if you need any further help with this. I will be happy to assist.
    If you find this helpful, Kindly mark the provided solution as "Accept Answer", so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-03-26T05:43:59.8533333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    In WPF System.Windows.Controls.DataGrid the event that corresponds to “row edit finished” is DataGrid.RowEditEnding.

    RowEditEnding fires before the edit is actually committed or canceled. In the handler, the DataGridRowEditEndingEventArgs argument exposes:

    • EditAction – indicates whether the row edit is being committed or canceled.
    • Cancel – can be set to true to keep the row in edit mode.

    Typical pattern to detect a successfully finished row edit and then push changes to the database:

    private void DataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
    {
        if (e.EditAction == DataGridEditAction.Commit)
        {
            // At this point the row is about to be committed to the DataTable.
            // Force commit of the current edit if needed
            var grid = (DataGrid)sender;
            grid.CommitEdit(DataGridEditingUnit.Row, true);
    
            // Now the underlying DataRow in the bound DataTable is updated.
            // Retrieve the item and send it to the database.
            var rowView = (DataRowView)e.Row.Item;
            DataRow row = rowView.Row;
    
            // Call data-access code here, e.g. update database with `row`.
        }
    }
    

    Key points:

    • Use RowEditEnding to know when a row edit is finishing.
    • Check e.EditAction == DataGridEditAction.Commit so database updates only occur on commits, not cancels.
    • Optionally call CommitEdit() to ensure the edit is fully committed to the bound DataTable before reading values.

    If more separation is desired, the commit logic can be moved to a method that takes the DataRow and performs the database update.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.