Datagrid current row edits

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Keith G

    #1

    Datagrid current row edits

    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.
  • Charlie Brown

    #2
    Re: Datagrid current row edits

    Keith,
    Can you post some of your code from the update event?

    Comment

    • Keith G

      #3
      Re: Datagrid current row edits

      Here is the code from the form which includes the Toolbar button events and
      the unsuccessful 'EndEdit'.

      Private Sub dsLoad()
      Me.ObjDsSupplie rList.Clear()

      Me.OleDbDataAda pter1.Fill(ObjD sSupplierList.T ables(0))

      End Sub

      Private Sub ToolBar1_Button Click(ByVal sender As Object, ByVal e As
      System.Windows. Forms.ToolBarBu ttonClickEventA rgs) Handles ToolBar1.Button Click

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

      dgtS.DataGrid.E ndEdit(dgtS.Gri dColumnStyles(M e.dgdSuppliers. CurrentCell.Col umnNumber), Me.dgdSuppliers .CurrentRowInde x, False)

      Select Case ToolBar1.Button s.IndexOf(e.But ton)
      Case 1
      dsLoad()
      Case 2
      If ObjDsSupplierLi st.HasChanges() Then
      Try
      OleDbDataAdapte r1.Update(ObjDs SupplierList)
      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

      "Charlie Brown" wrote:
      [color=blue]
      > Keith,
      > Can you post some of your code from the update event?
      >
      >[/color]

      Comment

      • Moumen VB.NET 2003/2005 Developer

        #4
        Re: Datagrid current row edits

        Hi,

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

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

        Public Sub UpdateDatasourc e(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.KeyboardFo cusView
        View.CloseEdito r() ' <=== VERY IMPORTANT Statement for any update
        If Not View.UpdateCurr entRow() Then Return
        'Update the database's table
        DoUpdateTable(O leDB, dataset11.Table s(TableName))

        'Update the database's table
        End Sub

        Public Sub DoUpdateTable(B yVal dataAdapter As DbDataAdapter, ByVal
        dataTable As System.Data.Dat aTable)
        dataAdapter.Upd ate(dataTable)
        End Sub

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

        I hope this helps you.

        Regards

        "Keith G" wrote:
        [color=blue]
        > Here is the code from the form which includes the Toolbar button events and
        > the unsuccessful 'EndEdit'.
        >
        > Private Sub dsLoad()
        > Me.ObjDsSupplie rList.Clear()
        >
        > Me.OleDbDataAda pter1.Fill(ObjD sSupplierList.T ables(0))
        >
        > End Sub
        >
        > Private Sub ToolBar1_Button Click(ByVal sender As Object, ByVal e As
        > System.Windows. Forms.ToolBarBu ttonClickEventA rgs) Handles ToolBar1.Button Click
        >
        > Dim dgtS As DataGridTableSt yle = Me.dgdSuppliers .TableStyles(0)
        > 'complete any edits
        >
        > dgtS.DataGrid.E ndEdit(dgtS.Gri dColumnStyles(M e.dgdSuppliers. CurrentCell.Col umnNumber), Me.dgdSuppliers .CurrentRowInde x, False)
        >
        > Select Case ToolBar1.Button s.IndexOf(e.But ton)
        > Case 1
        > dsLoad()
        > Case 2
        > If ObjDsSupplierLi st.HasChanges() Then
        > Try
        > OleDbDataAdapte r1.Update(ObjDs SupplierList)
        > 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
        >
        > "Charlie Brown" wrote:
        >[color=green]
        > > Keith,
        > > Can you post some of your code from the update event?
        > >
        > >[/color][/color]

        Comment

        • Keith G

          #5
          Re: Datagrid current row edits

          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 KeyboardFocusVi ew 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?!!


          "Moumen VB.NET 2003/2005 Developer" wrote:
          [color=blue]
          > Hi,
          >
          > I had this problem before, and I solved it with the following procedures:
          >
          > =============== ==============
          >
          > Public Sub UpdateDatasourc e(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.KeyboardFo cusView
          > View.CloseEdito r() ' <=== VERY IMPORTANT Statement for any update
          > If Not View.UpdateCurr entRow() Then Return
          > 'Update the database's table
          > DoUpdateTable(O leDB, dataset11.Table s(TableName))
          >
          > 'Update the database's table
          > End Sub
          >
          > Public Sub DoUpdateTable(B yVal dataAdapter As DbDataAdapter, ByVal
          > dataTable As System.Data.Dat aTable)
          > dataAdapter.Upd ate(dataTable)
          > End Sub
          >
          > =============== =============== ==
          >
          > I hope this helps you.
          >
          > Regards
          >
          > "Keith G" wrote:
          >[color=green]
          > > Here is the code from the form which includes the Toolbar button events and
          > > the unsuccessful 'EndEdit'.
          > >
          > > Private Sub dsLoad()
          > > Me.ObjDsSupplie rList.Clear()
          > >
          > > Me.OleDbDataAda pter1.Fill(ObjD sSupplierList.T ables(0))
          > >
          > > End Sub
          > >
          > > Private Sub ToolBar1_Button Click(ByVal sender As Object, ByVal e As
          > > System.Windows. Forms.ToolBarBu ttonClickEventA rgs) Handles ToolBar1.Button Click
          > >
          > > Dim dgtS As DataGridTableSt yle = Me.dgdSuppliers .TableStyles(0)
          > > 'complete any edits
          > >
          > > dgtS.DataGrid.E ndEdit(dgtS.Gri dColumnStyles(M e.dgdSuppliers. CurrentCell.Col umnNumber), Me.dgdSuppliers .CurrentRowInde x, False)
          > >
          > > Select Case ToolBar1.Button s.IndexOf(e.But ton)
          > > Case 1
          > > dsLoad()
          > > Case 2
          > > If ObjDsSupplierLi st.HasChanges() Then
          > > Try
          > > OleDbDataAdapte r1.Update(ObjDs SupplierList)
          > > 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
          > >
          > > "Charlie Brown" wrote:
          > >[color=darkred]
          > > > Keith,
          > > > Can you post some of your code from the update event?
          > > >
          > > >[/color][/color][/color]

          Comment

          Working...