locked
Refreshing a GataGrid via RIA Services and a DomainContext RRS feed

  • Question

  • I am displaying a database table using L2S and RIA Services.  This is being done in the XAML, in a manner identical to the methods reviewed in the RIA Services Overview for the July bits.

    I have added a "Refresh" button, so that the user can cause the DataGrid to be refreshed.  When the refresh button is pressed I am reloading the data via: this.MyDataContext.Load().  MyDataContext is defined in the XAML. 

    The results are that new rows are correctly displayed in the DataGrid when it is refreshed, but existing rows are not updated if their data has changed.  How do I get the existing rows to be displayed correctly?. 

    Monday, August 24, 2009 11:47 AM

Answers

  • By default, the DDS loads with a MergeOption of KeepCurrentValues.  As the least destructive MergeOption, that is the correct default. To change the MergeOption you need to handle the dds.LoadingData event. Within that event you can change the MergeOption in the LoadingDataEventArgs.

    Thursday, August 27, 2009 9:07 AM

All replies

  •  check my earlier link on

    http://silverlight.net/forums/t/99945.aspx

    You need to assign to DataGrid = null or some temp obj for a while then you can assign again MyDataContext this one is wiered solution but working fine.

     

    Thanks,

    Abhinay.

    Monday, August 24, 2009 1:32 PM
  • If I set the ItemsSource of the DataGrid to NULL, then set it back to the DDS, then it does not refresh the DataGrid.

    I would hope that there would be some way of forcing the DDS to reload the data (does not look like it does when I call the Load() method of the DDS.  Either that, or the data is being reloaded, but the DataGrid does not show the changed data.

     

    Monday, August 24, 2009 2:08 PM
  •  

     Hello,

               You can use the "dds.SubmitChanges();" , where dds is the domain data source. You can write this code on the refresh button click.

     

    Mark as Answer if it helpful to u....

    Thanks,

    Pratixa

    Tuesday, August 25, 2009 3:08 AM
  • Calling SubmitChanges() does not cause the DataGrid to be refreshed.  The prior post was helpful, but not realisitic where the user can change multiple rows via a seperate window, then need the grid to be refreshed.  Without a solution, this exposes a real weakness in RIA Services, where refreshes after changes are very common in large database-driven applications.

    Tuesday, August 25, 2009 8:39 AM
  • Hi,

    DomainService.SubmitChanges() doesn't reload data, however, DomianDataSource does cause reload after submit changes. Please check this sample project

    http://code.msdn.microsoft.com/RiaServices/Release/ProjectReleases.aspx?ReleaseId=2387

    And you could get more information about DomainDataSource from Ria service overview document chapter 9.

    Thanks,

    Thursday, August 27, 2009 5:16 AM
  • Using the DomainDataSource does not cause the data to be successfully reloaded.  Here is the scenario:

     1. Display a datagrid using the DDS, just as described in chapter 9 of the overiew.

    2. Change the data in the database using another program, or manually using SQL Server Manager.

    3. User clicks a button to "refresh" the datagrid.

    4. Call dds.SubmitChanges(), followed by dds.Load().

    The new data that was added to the database DOES show up in the datagrid.  However, any data that was modified is NOT changed in the grid.  The original values continue to be shown.  If the datagrid is dismissed, and recreated, then the changed data IS displayed correctly.  However, I do not want to force the user to dismiss the window, and reenter it in order for the modified data to be displayed correctly.

    I believe this to be a major weakness in RIA Services if there is not a suitable workaround.  Data refresh is a requirement of many applications, especially using datagrids.

     

     

    Thursday, August 27, 2009 8:59 AM
  • By default, the DDS loads with a MergeOption of KeepCurrentValues.  As the least destructive MergeOption, that is the correct default. To change the MergeOption you need to handle the dds.LoadingData event. Within that event you can change the MergeOption in the LoadingDataEventArgs.

    Thursday, August 27, 2009 9:07 AM
  • Thanks Colin! I just faced this scenario and used your idea, but i didn't handle the "LoadingData" event. I just used the "Load" method with passing "LoadBehavior.RefreshCurrent" as parameter. Here is the code i used to refresh entites when needed: DataSource.Domain.Load(DataSource.Domain.GetStatusDataQuery(), LoadBehavior.RefreshCurrent, false); PS: "DataSource" is just a wrapper class I use...
    Tuesday, November 24, 2009 7:41 AM
  • I just tried LoadBehavior.RefreshCurrent, as per Colin, and using took1's suggestion, and it seems to work. 

    This was a helpful thread.  Thanks to all.

    Saturday, May 8, 2010 7:12 PM
  •         public void Execute(object parameter)
            {
                DomainDataSource dds = parameter as DomainDataSource;

                if (dds != null)
                {
                    dds.LoadingData += new EventHandler<LoadingDataEventArgs>(dds_LoadingData);
                    dds.Load();
                }
            }

            void dds_LoadingData(object sender, LoadingDataEventArgs e)
            {
                e.LoadBehavior = LoadBehavior.RefreshCurrent;
            }

    worked for me, thanks colin

    Sunday, November 28, 2010 3:26 PM