Ok here is the deal, we allow multiple forms to be opened at once. If a user deletes an entity in one form that is being used by another form we have to refresh the other form. Now since there are about 15 forms in our application and all 15 can be opened at once you can then imagine the matrix of refreshes we need to do.
My question is this.. Is there a way or a framework out there that can handle autofreshing other forms.
For example. If we have a customers table in memory and form1/grid is binded to a linq query off of that table and then we have form2/grid binded to a linq query off of that table as well (but a different subset), and then I update grid1, thus updating the customers table object, and if I did that an auto notification would get sent out to all queries that are joined to that table?Or do I really have to keep this matrix of what to refresh?
The problem is my app is very similiar to having multiple related worksheets in an excel workbook, but I am not going to relate grids because they can close any form at anytime. This is what our users want, and it is annoying as hell.
Any help would be grealty appreciated.
Are you using Windows Forms data binding to populate the information in yoru forms? If so, you can probably use the binding manager to do this work for you.
To do this, all of the controls that you want to be refreshed automatically based on changes to each other must share the same binding context. Generally, a control shares the binding context of its form, and each form has its own binding context. You can make multiple forms share a single binding context by setting the BindingContext of one to match the one on an existing form. This is generally best done when the new form is opened.
For instance, I have two Form classes. Form1 is the root form of my application, and I show Form2 as a separate child form. The following C# code gives me a new instance of Form2 and makes it share the binding context of Form1 ("this" in the below example):
Form2 newForm = new Form2();newForm.BindingContext = this.BindingContext;newForm.Show();
Now, whenever I update a control on my new Form2 instance, any databound controls bound to the same data source will be updated on Form1, as if all the controls were on the same form.
You can likely find more resources describing this approach on MSDN.
What if form 1 controls are bound to a linq query from object Customers and form2 is bound to a linq query from Customers, so there source object is the same, but the bindings are different.
So long as they're bound to the same object, both will update automatically.
What you've describd sounds like you have objects from two different LINQ queries, which happen to pull data from the same underlying data store. In this scenario, updating one will not automatically update the other. This would be the case whether the application has one form or many forms, regardless of how you set your binding context.
If you can get the objects and controls to remain in sync on a single form, then the approach I described above will keep them in sync on multiple forms. You may also have to pass references to your data source from one form to another, whether through parameters of method calls or through proprerties on one of your form objects, so that you can bind different UI controls to the same data source.