我正在使用绑定到DataGrid的矩阵DataTable。在单击其他行之前,单元格编辑不会提交到DataTable。当任何单元格获得焦点时,如何提交更改?
答案 0 :(得分:3)
感谢CodeFluff的回答。我已经将它改编为VB.Net并在关闭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