I have the following code that refreshes the datagrid in the form after the update is made to the database. My question is why do I have to clear the datasource and then re-add it to get the changes to display. I would think that the refresh method would do this, but I can’t seem to get that to work. Is there a more efficient way to refresh the datagrid rather than resetting the datasource?
Public Sub addPlan(ByVal planname, ByVal plannumber)
Dim planinfo As New changeDatabase(planname, plannumber, planAdapter)
planinfo.addPlan()
Form1.DataGridView1.EndEdit()
Form1.DataGridView1.DataSource = ""
Form1.DataGridView1.DataSource = planAdapter.GetData()
End Sub
Try creating an explicit
BindingSourceand assign a datasource to it, then set theDataGridView’s DataSource property to the BindingSource instance.The
BindingSourceobject’sResetBindingmethod will cause theDataGridViewto reread all the items in the list and refresh all displayed values.Note: Passing false means that only values have changed in the original datasource, true means that the schema of the data has changed.