Subforms in C#

I have a form which was built using MS Access. It contains continuous subforms. Is there anyway in C# to have subforms in a form in the way you can with MS Access?
LVL 1
IdaracAsked:
Who is Participating?
 
Fernando SotoConnect With a Mentor RetiredCommented:
In C# what you are asking is called a UserControl or also called a Composite control. A user control is a control that has one or more controls laid out in a container. For example it could have TextBox, CheckBox, ComboBox, Label controls in a layout of your design. When this control is compiled it gets placed in the Toolbox of the designer, at this point the control can be added to your project form or added programmatically in code. To make it look more like Access you can add the control to a FlowLayoutPanel. See the following article Walkthrough: Authoring a Composite Control with Visual C# for how to create UserControl/Composite control.
0
 
Fernando SotoRetiredCommented:
Hi Idarac;

If you are asking if a Form can crate another Form which can also crete another Form then the answer is yes, all you beed to do is design it that way.
0
 
IdaracAuthor Commented:
OK do you know how to insert (embed) a subform into a form?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
However, you cannot "embed" a form in another in C#, at least to my knowledge, the way you can with Access. You could create a "main form" that shows your main records, and a second form that shows the "child" records, and then position the child form on the main form.

But this is something you'd have to handle, of course. Access does this for you, but C# will not.

Or you could use a grid control on the C# form to emulate the child records for the main form.
0
 
IdaracAuthor Commented:
Hi Scott that sounds like a plan.

Can you point me to an example of how to emulate using the grid control?
0
 
Fernando SotoRetiredCommented:
Hi Idarac;

Yes you can embed a Form in a Form in a Form.  A Form is just like any other control with extra responsibilities. Here is a screen shot of a Form3 embedded into Form2 which is embedded into Form1 and all controls on all forms work.

A Form embedded into another Form
0
 
Fernando SotoRetiredCommented:
Hi Idarac;

Of course if you're design goals is to display Data from a database such as Access you can use controls from the C# Toolbox to create a master detail view of the data without embedding a Form into another Form. Tell us what you need to do.
0
 
Fernando SotoRetiredCommented:
Hi Idarac;

Here is an example of building a master detail DataGridView using an Access 2007 database.

Basics of manually creating a Master-Detail view of a backend database
0
 
IdaracAuthor Commented:
Fernando

Here is a screenshot of the form I am trying to build.

-I
AreasExample.png
0
 
IdaracAuthor Commented:
In Access it is called continuous a subform.
0
 
IdaracAuthor Commented:
Worked great sorry for my slow response.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.