Datagridview update problem

Posted on 2005-04-10
Last Modified: 2010-05-19
The datagridview is bound to dataset1, and table Invoice.
after I edit cells, and click a "save" button to perform following:  
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?
Question by:gavvic
    LVL 14

    Accepted Solution

    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

    Author Comment

    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 2005, how can I show the last row when the form load? Thanks again.
    LVL 14

    Expert Comment

    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.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now