views:

6

answers:

2

Hi there, 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?

A: 

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;
krolley
A: 

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.

Kyle McClellan