1,105,399 Community Members

MDI Parent and Child form

Member Avatar
ZER09
Junior Poster in Training
90 posts since Jul 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello to all

I am playing with c# this past week, because i want to learn this language.

Now i have a question about my with my program.

First i have a 1 MDIparent form and 1 MDIchild form with one text box on it, then in the MDIparent I used a ribbon bar on it now i have also one button on the ribbon bar in the parent form, now what i want to do is that when the MDIChild form activated then i will type a text on the textbox on the childform after that i will click the button on the ribbon bar on the MDIparent form then after clicking on it a messagebox will appear with the text I input on the Child form. I already played on mdi parent and child but i cant find the solution on the text that will bypass from mdi child to mdi parent.

I will appreciate for any help will come. thank you

sorry for my bad English

Member Avatar
lolafuertes
Posting Shark
912 posts since Oct 2008
Reputation Points: 145 [?]
Q&As Helped to Solve: 196 [?]
Skill Endorsements: 7 [?]
 
0
 

Go to the child form properties, select the textbox and change his modifier to Public. This will make you textbox visible from the parent form.

Then on the parent form, use the childform.textbox.text to show the message.

Hope this helps

Member Avatar
ZER09
Junior Poster in Training
90 posts since Jul 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

how about if we will not changed the modifier, and it's still private and the parent form can access on it. i am thinking if it is possible to happen.

BTW i tried what you suggest but its not working.

thank you.

Member Avatar
lolafuertes
Posting Shark
912 posts since Oct 2008
Reputation Points: 145 [?]
Q&As Helped to Solve: 196 [?]
Skill Endorsements: 7 [?]
 
0
 

In order the parent form can access to some shild form data is that those data is public.

If you wish not to change the visibility of the control, you can add a read only property to the form, and the get will return the textbox text.

i tried what you suggest but its not working

Do you have an error? is not showing the contents?
Please, post your code here, and will try to help you.

Member Avatar
ZER09
Junior Poster in Training
90 posts since Jul 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

I have this code on my child form

public string texttest
        {
            get
            {
                return studentIDtextEdit.Text;
            }
            set
            {
                studentIDtextEdit.Text = value;
            }
        }

and this for my Parent form

private readonly student studentForm = new student();

private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            MessageBox.Show(studentForm.texttest);
        }

i was expecting that when i clicked the button on the parent form it will show me the message what i typed on the child form through the message box on the parent form. i have no idea why i will get an empty string on the message, the message box doesn't show any message.

I also tried to set the modifier of the text box into public but still i cant access it to another form on the parent form.

Member Avatar
Antenka
Posting Whiz
368 posts since Nov 2008
Reputation Points: 274 [?]
Q&As Helped to Solve: 86 [?]
Skill Endorsements: 9 [?]
 
0
 

Hello, ZER09.
Public property is enough to get this working. I've tried, and it displayed all I wanted. Can't say why yours is acting wrong. Can you provide a code, where you add a child form to a parent MDI container?

Member Avatar
ZER09
Junior Poster in Training
90 posts since Jul 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

i have this code in my parent form to call the child

student studentChild = new student();

private void newStudentbarButtonItem_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            student studentchildform = new student() { MdiParent = this };
            studentchildform.Show();
        }

then when i try to call the textbox from the child form called student

my code is like this

student.textbox.text;

or something like this

string teststring

teststring=student.textbox.text;

and i already set the modifier of the textbox to public

it still will get an error


pls help.

Member Avatar
Antenka
Posting Whiz
368 posts since Nov 2008
Reputation Points: 274 [?]
Q&As Helped to Solve: 86 [?]
Skill Endorsements: 9 [?]
 
0
 

Hmmm ..
How about this:

studentchildform = new student();
studentchildform.MdiParent = this;
studentchildform.Show();
Member Avatar
ZER09
Junior Poster in Training
90 posts since Jul 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

its still the same, nothing happens. it just gave an empty string.

Member Avatar
Antenka
Posting Whiz
368 posts since Nov 2008
Reputation Points: 274 [?]
Q&As Helped to Solve: 86 [?]
Skill Endorsements: 9 [?]
 
0
 

Please, post the full code, that you have at the moment (where you create MdiChild and when you work with it's text: get and output).

Member Avatar
lolafuertes
Posting Shark
912 posts since Oct 2008
Reputation Points: 145 [?]
Q&As Helped to Solve: 196 [?]
Skill Endorsements: 7 [?]
 
0
 

Agreed. Please post your full code.

The most common situation is that the child form has not been shown, just instantiated, when you try to get the value of the text box.

Let us know

Member Avatar
ZER09
Junior Poster in Training
90 posts since Jul 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

@antenka thank you i already solve the problem. but i have another problem

here is the scenario:

now the scenario is that, there is two child form opened and both of them has a textbox and both of the textbox has a text or a data(string), then only one of the child forms are active and the other one is inactive. now when i clicked the button or menu in the parent form, only the text from the textbox of the active child form will be shown (example in the messagebox), and the text from the inactive child forms will be disregard.

can you help about this. thank you

Member Avatar
Antenka
Posting Whiz
368 posts since Nov 2008
Reputation Points: 274 [?]
Q&As Helped to Solve: 86 [?]
Skill Endorsements: 9 [?]
 
0
 

already solve the problem

Please, post your code, so the other people who would face the same problem - will easily find the solution.

can you help about this

Take a look at Determining the Active MDI Child

Member Avatar
ZER09
Junior Poster in Training
90 posts since Jul 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

this is my code

for the parent form

public static string teststring = "";

        public string a // this will be called by the child form
        {
            set
            {
                teststring = value;
            }
        }

        public mainform()
        {
            InitializeComponent();
        }

private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //it will now show the data
            MessageBox.Show(teststring);
       
        }

for the child form

public student()
        {
            InitializeComponent();
        }



private void studentIDtextEdit_EditValueChanged(object sender, System.EventArgs e)
        {

// at this point it will send the data to the parent form
            mainform mnf = new mainform();
            mnf.a = studentIDtextEdit.Text;
        }

all the modifier is set to private

Take a look at Determining the Active MDI Child

i cant understand it so will, can you please give more hint about it

thank you

Member Avatar
lolafuertes
Posting Shark
912 posts since Oct 2008
Reputation Points: 145 [?]
Q&As Helped to Solve: 196 [?]
Skill Endorsements: 7 [?]
 
0
 

I did'nt understand why in the child form you instantiate the parent form. Isn't instantiated before? What is the order of appareance of the forms?

Member Avatar
ZER09
Junior Poster in Training
90 posts since Jul 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Actually i want to pass the data from the child form to the parent form
so i instantiate the parent form to the child form

mainform mnf = new mainform();
mnf.a = studentIDtextEdit.Text;

so that i can pass the data to the parent form by setting it

public string a // this will be called by the child form
        {
            set
            {
                teststring = value;
            }
        }

then it will be shown in the message box on the parent form

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: