none
Refill Datagrid after updating different dataset

    Question

  • I have two typed Datasets both bound to a different DGV, one in form1 other in form 2.
    After changing the Data in the Grid2 on form2, I want the Grid1 in form1 to be refreshed.
    Grid1 is created by a Stored Procedure on my SQL-Server.
    For creating everything, I used drag & drop and the wizards.
    I have tried already putting the following code to the save button in the menustrip in DGV2 or putting the code into the Load_Form of form1:

    Dataset1.table.clear()
    DGV1.datasource = Nothing
    tablebindingsource.datasource = tableadapter.getdata()
    tableadapter.fill(dataset2.table)
    bindingsource.resetbindings(false)

    something else i tried was:

    Public Sub RefreshData()       

    Me.DataSet.table.Clear()       

    Me.TableAdapter.Fill(Me.DataSet.table)       

    Me.BindingSource.DataSource = Me.DataSet.table    

    Me.BindingSource.ResumeBinding()           

    End Sub

    and the last thing i tried:

    Public Sub sproc_value_transfer()        
    Dim conn As New SqlConnection("Data Source=XXX\SQLEXPRESS;Initial Catalog=a;Integrated Security=TRUE")       
    Dim strSQL As String = "dbo.storedProc1"
    conn.Open()       
    Dim da As New SqlClient.SqlDataAdapter(strSQL, conn)
    Me.DataSet.table.Clear() 
    da.Fill(Me.DataSet.table)       
    conn_veko.Close()        
    DataGridView.DataSource = Me.DataSet.table  
    End Sub
    but all this is not working. I am quite desperate. I do not get an error but DGV2 is not refilled until the program restarts.

    I would be so happy if at least anyone could give me an advise or a hint.

    cordially

    Tuesday, July 16, 2013 7:47 AM

Answers

  • ok, here is the solution

    Private Sub Form_Activated(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MyBase.Activated
        Form_Load(Nothing, Nothing)
    End Sub
    Anyone who can explain we why this works and nothing of the code above?
    Wednesday, July 17, 2013 8:40 AM
  • Hi Ruediger007,

    Form.Load event occurs before the form is first displayed, however Form.Activated event occurs when form is activated every time.

    If you have changed the data source, you need to reset the DataSource. So Load event will work only for the first time. Activated event will work every time form is activated.

    Best regards,


    Chester Hong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Friday, July 19, 2013 2:32 AM
    Moderator

All replies

  • ok, here is the solution

    Private Sub Form_Activated(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MyBase.Activated
        Form_Load(Nothing, Nothing)
    End Sub
    Anyone who can explain we why this works and nothing of the code above?
    Wednesday, July 17, 2013 8:40 AM
  • Hi Ruediger007,

    Form.Load event occurs before the form is first displayed, however Form.Activated event occurs when form is activated every time.

    If you have changed the data source, you need to reset the DataSource. So Load event will work only for the first time. Activated event will work every time form is activated.

    Best regards,


    Chester Hong
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Friday, July 19, 2013 2:32 AM
    Moderator