I use the following code to populate a GriveView control. As you can see oBundleEntriesDAL.GetByBundleID returns an IQueryable object which is used to set GridView.DataSource.
Private Sub PopulateBundleEntries()
Dim oBundleEntriesDAL As New BundleEntriesDAL(_ContextConnection)
gvBundleEntries.MasterGridViewTemplate.AutoGenerateColumns =
False
gvBundleEntries.DataSource = oBundleEntriesDAL.GetByBundleID(_BundleID)
End Sub
Public Function GetByBundleID(ByVal bundleID As Integer) As IQueryable(Of BundleEntry)
Dim query = From bundleEntries In _Context.BundleEntries.Include("Bundle") _
Where bundleEntries.Bundle.BUNDLE_ID = bundleID _
Select bundleEntries
Return query
End Function
I have a form that calls PopulateBundleEntries() when the form is loaded. Later, if I add a row to the underlying database and call PopulateBundleEntries() again the row appears in the GridView control as it should. However, if I change some column values for an existing row in the database and call PopulateBundleEntries() again the changes in the database are not reflected in the GridView. I have tried clearing the rows before DataSource is set but that doesn't resolve the problem. I tried using Rows.Clear and Rows.RemoveAt but neither of those options worked.
What am I doing wrong? How do I get the GridView to display column values that have CHANGED in the underlying database?
Steps to Reproduce Problem
1) Populate GridView in Forms Load Event (call PopulateBundleEntries())
2) Add a row to database and refresh the grid to reflect the change (call PopulateBundleEntries())
3) Change column values for existing row in the database and refesh the grid to reflect the change (call PopulateBundleEntries())