• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 561
  • Last Modified:

Datagridview update problem

The datagridview is bound to dataset1, and table Invoice.
after I edit cells, and click a "save" button to perform following:  
OleDbConnection1.Open()
Me.OleDbDataAdapter2.Update(DataSet1.Invoice)
OleDbConnection1.Close()
the datagridview doesn't update the last record(last cell). But if I press key Enter before click "save" button, all changes including the last record will be saved in the database. How can I fix this problem, and how to perform this Enter action by code?
0
gavvic
Asked:
gavvic
  • 2
1 Solution
 
amyhxuCommented:
One way to get around this is:

keep track of the cell you were in:
    Dim rowNo As Integer
    Dim colNo As Integer

    Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged

        rowNo = DataGrid1.CurrentCell.RowNumber
        colNo = DataGrid1.CurrentCell.ColumnNumber

    End Sub

In your DataGrid1.Leave event, save the content in the last cell to dataset:
    Private Sub DataGrid1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Leave

        myDataSet.Tables("myTable").Rows(rowNo)(colNo) = DataGrid1.Item(rowNo, colNo)

    End Sub
0
 
gavvicAuthor Commented:
Thanks amyhxu. I have fixed the problem now, I should use a button not a toolstrip to preform this "save".
Could you mind to answer my another question?  I am using Datagridview of VB.net 2005, how can I show the last row when the form load? Thanks again.
0
 
amyhxuCommented:
Sorry I haven't used .net 2005, and I have no idea what a datagridview look like. Other experts may be able to help you on this issue.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now