Search code examples
c#silverlightdatagridrefreshwcf-ria-services

How to refresh DataGrid?


I am working on Silverlight 5 and RIA Services for database operations. DataGrid showing data perfectly.

But when I delete a record and submit changes to database, database updating successfully, but DataGrid showing still old data. It is not refreshing.

I search on google and surprise to see that there is no simple answer and I am also surprise to see that microsoft has not provided this basic functionality in Silverlight.


Solution

  • It is not a good way by anymeans, but I have gotten around this by setting the DataGrid to null and the re-adding the data.

     System.Collections.IEnumerable temp = yourGrid.ItemsSource;
     yourGrid.ItemsSource = null;
     yourGrid.ItemsSource = temp;
    

    I do not like doing it this way but it works and for my purposes I have not noticed any performance hits.

    Edit: I guess this may not work with a delete though, but worth a try