Datagrid current row edits

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

VS2003
I am using a datagrid on a Windows form.
The user has 2 buttons: cancel the current changes (re-loads the dataset)
or update (updates the dataset).
The problem is that any edits in the current row are not included in the
update.
The user has to click out of that row before updating. If this is not done
and the 'current row' remains selected after the update, the user will see
the edited row and assume it has been included in the update.
I have tried moving the focus before updating and even EndEdit to try to
force the current row to accept any changes - but without success.

Has anyone got any suggestions?
Thanks in advance.
 
Here is the code from the form which includes the Toolbar button events and
the unsuccessful 'EndEdit'.

Private Sub dsLoad()
Me.ObjDsSupplierList.Clear()

Me.OleDbDataAdapter1.Fill(ObjDsSupplierList.Tables(0))

End Sub

Private Sub ToolBar1_ButtonClick(ByVal sender As Object, ByVal e As
System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick

Dim dgtS As DataGridTableStyle = Me.dgdSuppliers.TableStyles(0)
'complete any edits

dgtS.DataGrid.EndEdit(dgtS.GridColumnStyles(Me.dgdSuppliers.CurrentCell.ColumnNumber), Me.dgdSuppliers.CurrentRowIndex, False)

Select Case ToolBar1.Buttons.IndexOf(e.Button)
Case 1
dsLoad()
Case 2
If ObjDsSupplierList.HasChanges() Then
Try
OleDbDataAdapter1.Update(ObjDsSupplierList)
Catch ex As Exception
MsgBox("There were errors in the data. The table has
not been updated." & vbCr & ex.Message)
End Try

End If
End Select
End Sub
 
Hi,

I had this problem before, and I solved it with the following procedures:

=============================

Public Sub UpdateDatasource(ByVal OleDB As DataAdapter, ByVal grid As
GridControl, ByVal dataset11 As DataSet, ByVal TableName As String)
'Save the latest changes to the bound DataTable
Dim View As ColumnView = grid.KeyboardFocusView
View.CloseEditor() ' <=== VERY IMPORTANT Statement for any update
If Not View.UpdateCurrentRow() Then Return
'Update the database's table
DoUpdateTable(OleDB, dataset11.Tables(TableName))

'Update the database's table
End Sub

Public Sub DoUpdateTable(ByVal dataAdapter As DbDataAdapter, ByVal
dataTable As System.Data.DataTable)
dataAdapter.Update(dataTable)
End Sub

================================

I hope this helps you.

Regards
 
Thanks for your response.
However, I don't recognise GridControl or ColumnView as Controls, Classes or
Members.
Are these controls in VS 2005? I'm using VS 2003.
There doesn't seem to be the equivalent to the KeyboardFocusView and
CloseEditor members in VS 2003 (which appears to be the key to including the
current row edits in the update)
...... or am I in the wrong discussion group?!!
 
Back
Top