Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello

i have a c sharp application, which contains one child form "query builder" and this form should be called by multiple parent forms whenever it called.

Need Suggestion
Posted

What is the problem? Provided you have written your QueryBuilder form without any static variables and following sensible coding practices, then each instance will be independent, and you can open as many instances as you want.
 
Share this answer
 
Comments
Mayank Topiwala 10-Sep-11 5:28am    
ok here's my complete doubt :

Have one child form to pass data from the multiple MDI parent form to the child form on opening the child form. Once the child form is open, data can be passed back to the MDI parent forms by invoking a method in the child form.
The global Var :-
private Forms.Transactions.frmMatReq mdiParent1;
private Forms.Transactions.frmMaterialIssue mdiParent2;

form initialization :-

public frmQueryBuilder(string FormName)
{
InitializeComponent();
_FormName = FormName;
}

The application run properly with one parent form as i did the coding on click_button :-
this.mdiParent1.ChildMessage = Message;
this.mdiParent1.UpdateMessage(Message);
this.Close();

now give me the solution for mdiparent2..
OriginalGriff 10-Sep-11 5:40am    
So, you have two MDI forms, each with their own set of MDI child forms, and a completely separate QueryBuilder form which is not an child of either MDI form. You want a single instance of the QueryBuilder form to be accessible from either of the MDI Parent forms.

Or, the QueryBuilder is a MDI child of one of the MDI parents, but you want to access it's data from both MDI parents?
Mayank Topiwala 10-Sep-11 5:55am    
yes the second one, the query builder is an MDI child which is called by multiple parent forms.

The app run with following:-
public frmQueryBuilder(string FormName,frmMatReq m1)
{
InitializeComponent();
this.mdiParent=m1;
_FormName = FormName;
}

but this is only for one form.
OriginalGriff 10-Sep-11 6:02am    
That isn't necessarily a good idea - it does suggest to the user that the inputs will be used on a single MDI parent - there is no way that normally what appears as a totally separate application would be affected by what you do to a MDI child in a different one.
Is there any particular reason why you want to do this? Because I can see it confusing users no end...
If you have to do it, then consider making your QueryBuilder a Singleton class - that would allow you to fetch the running instance of it from both forms. Google will help with that - it's a little complex, but a good idea if you really need this functionality. It found this article: http://www.codeproject.com/KB/architecture/singletonforms.aspx which should help.
C#
1) Create a form in the designer
2) in your button click do the following:
-----------------------------------------------------------------------------
form2 f = new form2();
f.ShowDialog();
 
Share this answer
 
The main problem in fetching the data from query builder form. This form could open in multiple parent forms.
 
Share this answer
 
I assume you have multiple MDI Forms and each MDI Form has a Menu?
Well, in the Click Event that opens your QueryBuilder Form you can do the following.

C#
public partial class frmMdiForm1 : Form
    {
        public frmMdiForm1()
        {
            InitializeComponent();
        }

        private void Button_Click(Object sender, EventArgs e)
        {
            Form frm = new frmQueryBuilder();
            frm.MdiParent = this;
            frm.Show
        }
    }

You probably have the same code in your second MDI Form.
C#
public partial class frmMdiForm2 : Form
    {
        public frmMdiForm2()
        {
            InitializeComponent();
        }

        private void Button_Click(Object sender, EventArgs e)
        {
            Form frm = new frmQueryBuilder();
            frm.MdiParent = this;
            frm.Show
        }
    }

Because both Click Events open a new QueryBuilder Form with their current parent Form as MdiParent your Forms should have their respective MdiForms as parent.
 
Share this answer
 
Comments
Mayank Topiwala 10-Sep-11 5:10am    
frm.MdiParent=this;

It doesn't work coz the parent forms already opened in another mdi form.
Sander Rossel 10-Sep-11 5:38am    
Not sure if I understand. The MdiParent Property of a Form can be ANY MDI Form, no matter if it is already a child of another MDI Form...

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