I have a grid on a form that is displaying records in table related to the form. To add a new record to this table, I display a popup form that inserts the new row, then call the method to refresh the grid (bind it to the new datasource) - code below:
Private Sub LoadActivity(ByVal ActiveLoadID As Integer)
Try
Dim UGActivity as UltraGrid
Dim m_LoadAct As New DataContext
Dim m_Activity = (From t In m_LoadAct.LoadActivities
Where t.LoadID = ActiveLoadID
Order By t.LastUpdated Descending
Select t.LoadActivityID, t.Carrier.CarrierName, t.ContactName, t.ContactPhone, t.Price, t.Notes, t.LastUpdated)
UGActivity.DataSource = m_Activity
m_LoadAct.Dispose()
End Try
End Sub
This gets called when the form first loads and it works fine. When I add a new entry, I popup the form, add the row, then call this same method. When I do, the grid does not change. When I debug and step through, I see that the m_Activity datasource has the new row and after the UGActivity.Datasource = m_Activity line I see that the UGActivity grid has the new row in it, but still, the grid on the screen does not change. If I put a button on the form to call the above method, it refreshes just fine. What am I missing? There are 2 other grids on this form that are populated through this same/similar process and work just fine. What am I missing? Any help would be appreciated.
Thank you.
Jacob
1. Why are you disposing your DC ? All changes in the grid will be stored in the DC until you fire the DC.SubmitChanges()-Event
(Please correct me if I'm wrong)
2. When are your savin your changes back to the DB ? -> SubmitChanges
3. I never added and tried to change data in a grid without a Bindingsource. Don't know if this may be the problem.
I would suggest you this way:
private m_LoadAct As New DataContext
catch ex as exception
'todo: Exceptionhandling
private sub saveChanges 'Call it whenever you want to save the changes
try
m_LoadAc.submitChanges() 'you can also check for pendingChanges here