Question

In my application, I extract the Data of a Linq To SQL DataContext into a dictionary for easy use like so:

Jobs = dbc.Jobs.ToDictionary(j => j.Id, j => j);

Then I bind this dictionary to a BindingSource:

bsJob.DataSource = jobManager.Jobs.Values.ToList();

I refresh the DataContext and the Dictionary regularly for when new Jobs are added to the database (whether directly through the local application or the application running on a different machine):

dbc.Refresh(RefreshMode.OverwriteCurrentValues, dbc.Job);
Jobs = dbc.Job.ToDictionary(j => j.Id, j => j);

How can I update the BindingSource to accommodate the changes as well?

Was it helpful?

Solution

I don't see the relation from the Jobs class to the Customer class, so I'll assume you meant to type that and not jobManager.Customers.Values.ToList();

Assuming you already have some sort of event triggering your refresh, since you mentioned you updated "regularly", you can assign a new value to the BindingSource.DataSource property at that time just like you did originally.

dbc.Refresh(RefreshMode.OverwriteCurrentValues, dbc.Customer);
Customers = dbc.Customer.ToDictionary(c => c.Id, c => c);
bsJob.DataSource = jobManager.Jobs.Values.ToList();  //Assuming this statement was correct
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top