BSalita
BSalita

Reputation: 8961

How to Commit Cell Edit Upon Leaving Cell

I'm using a matrix DataTable bound to a DataGrid. Cell edits aren't committed to the DataTable until a different row is clicked. How can I commit changes when any cell gets focus?

Upvotes: 0

Views: 2845

Answers (1)

BSalita
BSalita

Reputation: 8961

Thanks to CodeFluff for the answer. I've adapted it to VB.Net and included a commit upon closing the Window.

Private EditCommited As Boolean

Private Sub MainWindow_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Me.Closing
    CommitEdit()
End Sub

Private Sub DataGrid1_CellEditEnding(ByVal sender As Object, ByVal e As System.Windows.Controls.DataGridCellEditEndingEventArgs) Handles DataGrid1.CellEditEnding
    CommitEdit()
End Sub

Sub CommitEdit()
    If Not EditCommited Then
        EditCommited = True
        DataGrid1.CommitEdit(DataGridEditingUnit.Row, True)
        EditCommited = False
    End If
End Sub

Upvotes: 3

Related Questions