Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Winforms cross form communication in MDI

Status
Not open for further replies.

jtrembla

ISP
Jul 6, 2006
104
US
My Application is MDI. I have grids on all of my child forms.

One of my child form (lets call in "total") contains a grid that is a summation of all of the other grids on the other child forms. When I change a value on one of the grids on the child forms I need the datasource of the "total" form to be updated. How can I do this?

I have a method on that "total" child form that fetches the new datatable to update its grid. How do I call it from other child forms? Also, is this the best way to do it?
Should I call a method on the parent form that executes the method on the "total" form?

method on total form
Code:
public void RefreshSales()
        {
            DataTable dtUpdated = new DataAccess().GetDataForGrid(IftProperties.IFTNo, IftProperties.Version, "Sales_Pivot");
            UltraGrid ugrid = this.ultraGridSales;
            
            //Merge changes 
            salesDataTable.Merge(dtUpdated, false);
            
            // Refresh grid, this does not redraw grid
            dtUpdated.Dispose();
        }

 
You could use the OnShown even of total?

Age is a consequence of experience
 
That was a good read. I have another winforms question perhaps you can answer.

In my application all of my data for the grids come from stored procedures that returns pivoted data from normalized joined tables.

When I update a cell in the grid, I send that one value back to a stored procedure which then returns a datatable of the new values (re-calculations are done on the backend with T-SQL), and I merge the returned datatable with the one binded to the grid (this reloads the grid with the updated data).

In my DAL I can either create a static dataset and bind a datatable in the dataset to a grid where I can just update the datatable in the dataset, this makes it easier to update the binded grids on other forms.

OR I can just return a datatable and bind that the the grid and just update it by merging it with another datatable. Problem here is I need to either implement your Observer Design pattern or go through the parent form to call a method on a given child form to update the "total" grid.

What do you think is the best solution?


 
on shown will not work, because you can show multiple child forms at once, I have horizontal/vertical docking of child forms in my app. Quite nice..
 
Each form should not know about the other form. This really goes for any application and it is the DEATH of most applications.

If you rely on a combo box or a grid to make your system work then you have no hope of upgrading. This is a view and should only be used to view your data - not manage it.

The next pattern to look into is the Model View Controller (MVC) pattern. If you can get your head into this concept the development world will change for you. You no longer care about a form or a grid or a combo box. They are not your system - your controllers and models are your system. You can then choose to share your solution via a win form, a web app, a web service, or some other cool technology that comes along tomorrow.

I hope that gives you some ideas.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top