nikel
nikel

Reputation: 653

How can I refresh DataGridView?

I'm trying to refresh datagridview after adding multiple records which were added programmatically, using bindingsource and datasource. My code:

Private Async Function RefreshData() As Task

    Await Task.Delay(15000)

    bs.EndEdit()
    daProducts.Update(dtProducts)

    DataGridView1.DataSource = Nothing
    DataGridView1.DataSource = bs 'Insert your DataSource here
    bs.ResetBindings(False)
    ...

When I call this function on form load event, it can't display any records.

Another thing is I get error if I don't use async function (because of setting DefaultCellStyle.Alignment).

My formload event: http://sudrap.org/paste/text/554747/

Upvotes: 2

Views: 411

Answers (1)

user_4685802
user_4685802

Reputation: 155

This might be helpful for you:

Private Sub updatedgv()
        Dim conn As New MySqlConnection(My.Settings.myConn)
        Dim da As New MySqlDataAdapter
        Dim ds As New DataSet
        Dim str1 As String = "select * from tableName"
        da.SelectCommand = New MySqlCommand(str1, conn)
        da.Fill(ds)
        conn.Close()
        ProductDataGridView.DataSource = ds.Tables(0)
End Sub

the explanation can be found in the link http://www.codeproject.com/Questions/372731/how-to-refresh-datagridview-in-vb-net

Upvotes: 2

Related Questions