Search code examples
silverlight-4.0wcf-ria-services

Silverlight 4 with RIA Services - Refresh Datagrid bound to CollectionView


Here is my situation:

I have a domain datasource in my Silverlight 4 page. I've pulled associated entities from RIA Services and displayed them on the same page using a collectionview.

In a button click event I insert/add an entity (see code snippet below).

How do I get the datagrid to refresh? What am I doing wrong?

I know the data is being inserted into the database just can't get the grid to refresh without leaving the page and coming back.

DomainContext ctx = new DomainContext();
foreach (<Entity> x in EntityList)
      {
        <Entity> y = new <Entity>
        {
          .... <set values>
        };             

        ctx.<Entity>.Add(y);

      }

      ctx.SubmitChanges();
      DomainDataSource.Load(); ;
      CollectionView.View.Refresh();               

Solution

  • My problem was adding "outside" my domaindatasource.

    Here is what I ended up doing:

    DomainContext ctx = (MyDDS)DomainDataSource.DomainContext; //new DomainContext();
    foreach (<Entity> x in EntityList)
      {
        <Entity> y = new <Entity>
        {
          .... <set values>
        };             
    
        ctx.<Entity>.Add(y);
    
      }
    
      ctx.SubmitChanges();
      ....
      private void MyDDS_SubmittedChanges(object sender, SubmittedChangesEventArgs e)
    {
      MyDDS.Load();
    }
    

    Not sure if this is the optimal way to do it but it worked for me.