Jump to content

how to bypass data from MDI child from to parent form

- - - - -

  • Please log in to reply
5 replies to this topic

#1
zer09

zer09

    Newbie

  • Members
  • Pip
  • 4 posts
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

#2
zer09

zer09

    Newbie

  • Members
  • Pip
  • 4 posts
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();

        }


but when i try this


MessageBox.Show(studentChild.textcontrol.text)


i will got an error


even i will try this


string teststring


teststring=studentChild.textcontrol.text;


i don't know what the problem with this. even i already set the modifier to public

pls help.

#3
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
You can pass data within the constructor

int data = 5;

student studentchildform = new student(data);
Of course, you have to change (or overrite) the constructor to accept a variable

Or you can set variable of the second form in public insted of private and do something like this

student studentchildform = new student();

studentchildform.publicVariable = 5;

studentchildform.Show();


Don't forget, you should always encapsulate your variable (so create public method, to change the private variable)

#4
zer09

zer09

    Newbie

  • Members
  • Pip
  • 4 posts
thank you it solve my problem. now i have new problem
here is a 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.

what i want is that to get the data (example: a string) from an active child form only.

can you give more hint

thank you

#5
Vaielab

Vaielab

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 547 posts
Not too sure to understand.
The user will click a button, this will open 2 new form
Each form will have a textbox, but the user will be able to enter text only from one of them,
Then when he close both window, you will get the data from the textbox he enter?

#6
zer09

zer09

    Newbie

  • Members
  • Pip
  • 4 posts

Vaielab said:

Not too sure to understand.
The user will click a button, this will open 2 new form
Each form will have a textbox, but the user will be able to enter text only from one of them,
Then when he close both window, you will get the data from the textbox he enter?

what i mean is that, the user opened two child form already (1 child form will open per clicked). Then the user input some text on a textbox in the first form (the active child form) then if the user clicked a button on the parent form the data from the active child form only will be save, disregarding the other inactive childform even they have data.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users