Reputation: 8961
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
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