我正在尝试使用绑定(bind)源和数据源添加以编程方式添加的多个记录后刷新 datagridview。我的代码:
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)
...
当我在表单加载事件上调用此函数时,它无法显示任何记录。
另一件事是,如果我不使用异步函数(因为设置 DefaultCellStyle.Alignment),我会收到错误。
我的表单加载事件:http://sudrap.org/paste/text/554747/
最佳答案
这可能对您有帮助:
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
解释可以在链接中找到 http://www.codeproject.com/Questions/372731/how-to-refresh-datagridview-in-vb-net
关于vb.net - 如何刷新 DataGridView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29715657/