If the data is bound, the data is changed in the DataGrid, click on the Toolbar button in the form to save, the last input data, if the focus is not removed, it will not be submitted when saved, only the transfer Can you submit it when you open!
Sooked a long time on 9CBS post, I found that many people are suggested that there is no toolbar, but use the Button control, the user COVIS interpretation is "Submitted the data with the control with the selected property. Maybe you can use Toolbar buttons or other Controls without the selected property submitted data. Because he can't be selected, he can't accept focus, the general buttons or controls can transfer the focus of other controls to themselves. From here. "Description: http: // Search.9cbs.net/expert/topic/52/5201/2003/4/21/1688615.htm
But because all of the author's Toolbar is already done, change the trouble and not beautiful, can you find other methods to achieve?
After some exploration, I found that the following method can be realized:
Public Sub SaveData () Checks if the current focus is on the DataGrid, handover cells and submit changes. If Me.ActiveControl.Parent.GetType Is GetType (DataGrid) Then Dim dg As DataGrid = CType (Me.ActiveControl.Parent, DataGrid) ChangeCurrentCell (dg) Me.BindingContext (dg.DataSource) .EndCurrentEdit () End If
..... Save code
End Sub
Public Function ChangeCurrentcell (Byval DG As DataGrid) AS Boolean Try Dim Temp as DataGridcell = DG.CURRENTCELL
Dg.currentcell = new DataGridcell (Temp.RowNumber, 0) Dg.currentcell = Temp Return true catch exception return false end
END FUNCTION