DataGridView update,  add and removed rows

Posted on 2007-08-08
Last Modified: 2013-11-05
hi there,
I'm new with this datagridview stuff but i'm trying to get this working.
I have set up a data grid view and i'm populating the data ok but the problem here is when i try to update delete and add rows any changes i do they are not comitt to the database. my question here is how do i enable this commans?

and also, is there a way to have a navigation pane already build in to place on my from?
Question by:jsctechy
    LVL 1

    Author Comment

    i just remenber to post the code i'm sorry =0

     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            cn = New SqlClient.SqlConnection(My.Settings.cnnJSVSDB)
            ds = New DataSet
            dv = New DataView
            ad = New SqlClient.SqlDataAdapter("SELECT CUSIP, SYMBOL, ADD_DATE, END_DATE, DROP_DATE, END_DROP_DATE FROM ADDS", cn)
            Dim commandBuilder As New SqlClient.SqlCommandBuilder(ad)
            ad.Fill(ds, "Production")
            dv.Table = ds.Tables("Production")

            Me.dgvAdds.DataSource = dv

            AddHandler dgvAdds.RowsAdded, AddressOf Added
            AddHandler dgvAdds.RowsRemoved, AddressOf Removed

        End Sub

     Private Sub Removed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowsRemovedEventArgs) 'Handles dgvAdds.RowsAdded
            ' Update the database with the user's changes.

        End Sub
        Private Sub Added(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) 'Handles dgvAdds.RowsAdded
            ' Update the database with the user's changes.

        End Sub
    LVL 34

    Accepted Solution

    It sounds as though the additions/removals have not been committed from the datagridview to the datatable when you call the update.  I'm not sure about that, because I've never used these events in that way.  But you can try

       CType(BindingContext(dv), CurrencyManager).EndCurrentEdit

    as the first line in each of your subs: or, if you do not want to change the declaration of dv so that it will be visible to code like that, you could try

       CType(BindingContext(dgvAdds.DataSource), CurrencyManager).EndCurrentEdit



    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    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…
    This video discusses moving either the default database or any database to a new volume.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    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

    16 Experts available now in Live!

    Get 1:1 Help Now