Click here to Skip to main content
16,022,418 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We are creating a new MDI application in C#.net 4.0 which has MDIParent and MDIChild Form.
MDi Child has grid whose values are stored in the data.cs class. Object of data.cs class is stored in MDIChild.
Now we want to print all values from data.cs to report.
As I am new to C#, give me suggestion how to access the object of data.cs file through MDIChild in report.cs file.

Thanks in advance.
Posted

While you can loop through for example Controls collection on a form, this feels like a design problem.

IMO you shouldn't use the data directly from different forms in your code. Instead try separating the logic and the data from the presentation (the window and it's controls). This would make it much easier to handle the data and would be more robust and maintainable solution.
 
Share this answer
 
If the Data class instance is stored in the MDI child class, then your report class instance need to have access to the specific Data instance either via the MDI child form instance or some other way.

Personally, I would prefer to keep the classes as separate as possible, and instead of looking at making the form data available to the report class, I would get the data in the MDI parent, and pass it to the Report class, probably as part of the constructor. This way, the report class does not need to know about the existence of the MDI parent, or Child (and possibly not about the Data class) - it just gets on with the job of handling data for reports. It can then be reused in other projects without changes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900