Diver Dan
Diver Dan

Reputation: 9963

silverlight domain datasource refreshed only after F5

I am using SL4 with WCF RIA services. I have a domain datasource which I am using to populate a listbox. I have attached a context menu attached to the list items that I want to trigger an update to a fields value in the database. so I am trying

EmployeeDetail employee = (EmployeeDetail)sender;
if(employee.EmployeeDetails!=null)
employee.formEmployee.CommitEdit();
dsEmployee.SubmitChanges();

So the code works ok I see the update in the database, however the listbox hasn't been refreshed. If I press F5 then I see the change in the silverlight application however what do I need to do to refresh the lists datasource?

Upvotes: 0

Views: 1367

Answers (2)

Kyle McClellan
Kyle McClellan

Reputation: 2029

If you want to manually refresh a DomainDataSource, you can use the Load() method. If you want to do it on every successful submission, you can subscribe to the SubmittedChanges event and immediately invoke a load.

Upvotes: 0

robertkroll
robertkroll

Reputation: 8794

The question is a little bit vague. If your listbox is bound to a collection of EmployeeDetail objects, and they are entities, they will be wrapped in an IObservableCollection<EmployeeDetail>, which means that your listbox should be updated whenever your list is updated in the code behind. However, if you really need to refresh manually, I find that this works:

IObservableCollection<EmployeeDetail> temp = employeeListBox.ItemSource;
employeeListBox.ItemSource = null;
employeeListBox.ItemSource = temp;

Upvotes: 1

Related Questions