Table<T> not refreshing RRS feed

  • Question

  • I have the following in my code:

    To explain:

    I have a Products BindingSource, which is bound to a ProductCategories BindingSource (its current record's children), which is bound to the ProductCategories table, which has a child table Products, which has a child table OrderDetails, which displays the Product field in a DGVCBC, which is bound to the Products table.

    My problem is that when I add a new record to the Products BindingSource, (ie inserting a new record into Products table) the changes do not show up in the DGVCBC's dropdown. SubmitChanges() was called, so the changes should be in the database, right? The changes do not show up in the Table<T> though. How can I get the dropdown to display the new record?

    Friday, August 5, 2011 2:45 PM

All replies

  • Hello,

    Based on my understanding, you can notice that your entity classes implement two important interfaces called INotifyPropertyChanging and INotifiPropertyChanged. I suggest you can check this article about changing notification in linq to sql.

    If I misunderstood, please feel free to let me know.

    Best Regards,

    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, August 9, 2011 4:05 AM
  • I'm not sure if that would solve the problem. It's a good idea, but it probably won't work here. I need some way to refresh the list of records in the table, and refreshing each record individually is not adequate.

    I will be on vacation for a few days, but I will try to do some more investigation soon.

    Tuesday, August 9, 2011 1:32 PM
  • Here is a bit of an update.

    SubmitChanges is being called (pretty sure), so that is not the issue. The data is in the database, but the datacontext seems to get out of sync. I think I could fix this if I created a new DataContext, but I have a lot of ties to one main datacontext, so this would be a pain to reconfigure everything.

    Is there a way to reload the data into a datacontext?

    Tuesday, August 16, 2011 5:23 PM
  • I would think the .Refresh method of the DataContext object would do the trick.  I was thinking somthing like this (untested and you will have to use the identifiers appropriate for you):

    _Database.Refresh(RefreshMode.OverwriteCurrentValues, _Database.Registrations)


    Brent Spaulding | Access MVP

    Tuesday, August 16, 2011 9:56 PM
  • doesn't that method refresh a record? i want to refresh a table.
    Tuesday, August 16, 2011 10:02 PM
  • hmm when googling datacontext.refresh i found references to the DataContext.ClearCache method. Internal, but still callable through reflection. Perhaps this would work? does anyone have experience with this?

    Tuesday, August 16, 2011 10:10 PM
  • doesn't that method refresh a record? i want to refresh a table.

    The Refresh method has 3 overloads.;k(TargetFrameworkMoniker-%22.NETFRAMEWORK%2cVERSION%3dV3.5%22);k(DevLang-CSHARP)&rd=true

    You should be able to pass the table ... I can't "play" right now, but in the sample line if code, the second argument is a table

    Brent Spaulding | Access MVP
    Tuesday, August 16, 2011 10:32 PM
  • This is the overload I would suggest ...

    Brent Spaulding | Access MVP
    Tuesday, August 16, 2011 10:33 PM
  • But... doesn't this refresh all the items in the Table? Umm... did you read my OP? the problem is with INSERT, not UPDATE. The inserted records do not appear.
    Tuesday, August 16, 2011 10:37 PM
  • I did read your original post but apparently I am going after the wrong thing <dazed> ...

    So ... do tag each new entity with the call to .InsertOnSubmit() before you call .SubmitChanges()?  Also, do you reset your bindings for the DGVCBC after a successful .SubmitChanges()?.  Although that (reseting the bindings to the combo) my not be necessary --- sorry --- I wish I was able to use VS at my work station!

    Brent Spaulding | Access MVP

    Tuesday, August 16, 2011 10:51 PM
  • I do not call InsertOnSubmit on the new items. They are bound through a BindingSource. And there is no BindingSource for the DGVCBC to reset. The diagram shows this. Maybe I should mention that the 2 BindingSources in the left have DGV's connected to them.
    Tuesday, August 16, 2011 11:08 PM
  • Ahh ... the diagram ... I am on a different PC now and the diagram shows now, I think my workplace block images by default.  As far as adding data through a DGV, when I have added data through a DGV that is bound to a LinqToSQL entity set, I have had to identify each new row in the DGV, cast it as the LinqToSQL entity that is bound to the DGV as I pass it to the .InsertOnSubmit data context method, then call .SubmitChanges().  Note that you can call .InsertOnSubmit() more than once (like for each new row) prior to .SubmitChanges()  By doing that I am able to keep the cache and db in sync.  I will look for that code when I did it last (its been a while), or I will try to toss a sample together soon.

    Maybe it would be good to show how you save your new entities.

    Also ... you said:

    " I need some way to refresh the list of records in the table, "

    And I replied with the mentioned overload on the .Refresh method .. and you replied:

    " But... doesn't this refresh all the items in the Table? "

    So, I thought that is what you wanted to do.


    I am thinking that I am not understanding some of what you want <dazed> ... hopefully, with a re-read of the entire thread, with the diagram now visible to me, we can get to the root of what I think your asking --- to get the NEW Products listed in the combo of your datagrid view!  But first, lets make sure the data gets to the database table and the entity collection.

    Brent Spaulding | Access MVP
    Wednesday, August 17, 2011 2:17 AM
  • As a side note to all this, please understand that I am a C# novice (Access Development, SQL Server, and T-SQL is my forte) and have not been exposed to vast array of experiences with C#, so ... well take that however you wish...
    Brent Spaulding | Access MVP
    Wednesday, August 17, 2011 12:09 PM
  • Also ... you said:

    " I need some way to refresh the list of records in the table, "

    My bad. English is so ambiguous.... :)

    I guess I am a novice too, though less with C# and more with technologies like LINQ-to-SQL. Sometimes the pros start to get kinda heady, so novices are nice, too.

    I think you understand my situation pretty well. If you have any more suggestions, please post them. I think I may have to resort to ClearCache.

    Wednesday, August 17, 2011 1:58 PM
  • I had a chance to look over my app where I bind a DGV to LinqToSQL entities ... something that caught my eye was the fact that when I modified some data programatically, I called the .ResetItem(itemIndex) method of the BindingSource object to "refresh" what the DGV was displaying.

    My code snippet ...

    //refresh the items in the binding source
    foreach (int i in rowIndex)

    rowIndex is an array if int's.  The values in the array are the row indexes in the DataGridView (which, btw, corespond to the item index in the BindingSource object) that needed to be "refreshed".

    Here is the help article: BindingSource.ResetItem method

    Its a longshot, but it might help ... I was looking for something the might invalid that combo box and cause it to fetch the data again.

    Any luck with the ClearCache? 

    Brent Spaulding | Access MVP
    Thursday, August 18, 2011 7:57 PM
  • This might work, but it probably would be the wrong answer on a test, mainly because I would have to trap a DGV's actions to follow what it was doing etc.

    I wasn't working on the project today, so I didn't try ClearCache yet. So far no one has pointed out why it is not publicly accessible, so I will try calling it through reflection. I may not get back to this until sometime next week, so don't become alarmed if I don't update.

    Thursday, August 18, 2011 8:11 PM
  • >>  so don't become alarmed if I don't update. <<

    No alarms here! ... Heck -- I have 9 kids and getting ready to move to a new house, so --- definately no expectations from me!

    Brent Spaulding | Access MVP
    Thursday, August 18, 2011 8:18 PM
  • Please let me know if you solved your problem and if so how.

    I have exactly the same problem and have found a way to work around it that works but is NOT elegant.  

    My application is a WPF application and has a Main Xaml.   All my controls are loaded through the Main Xaml which share the same context that is passed to them in an environment variable after they are loaded.   My DataGrid and my combo boxes are all bound to a Collection View Sources.  I am using a context and the Entity Data Model

    FRUSTRATION - on updates in the datagrid that manage the lookup tables the changes ARE AUTOMATICALLY reflected in all of the combo boxes with NO EXTRA CODE.  on inserts in the datagrid I have to manage the refresh through a lot of code.


    On a save I Refresh the the data store with the new records and reset the context for the whole application to the new context.

                context.Refresh(RefreshMode.ClientWins , context.directoryNames);
                context.Refresh(RefreshMode.ClientWins, context.directoryNames);

                myEnvironment.myContext = new MNSAppGenEntities();   // This forces a refetch of all of the data from the datastore
                context = myEnvironment.myContext;

    My environment has a link to the parent (Main XAMLcontrol)   The children have a public refresh method exposed and the


    The refresh method for the drop down goes to each user control that is dependent on the lookup table in the datagrid and reloads them with the new data context that has been set in the datagrid window.

    If you have found a better way let me know.  If not I hope that this is helpful.

    Monday, September 26, 2011 9:40 PM