4 Attachment(s)
Parent to Child Dialog Data Transfer & Vise Versa in VC++
Hi,
I transferred data from parent to child.
problem occurred while send data from child to parent dialog.
Kindly find the attachment & help me.
void CChildDlg::OnBnClickedCancel()
{
child1ctrl.GetWindowText(parObj.parentval);
::AfxMessageBox(parObj.parentval);
//parObj.parentctrl.SetWindowText(child1val);
if(UpdateData(true))
{
((CTestDlg*)m_pParent)->parentval = child1val;
((CTestDlg*)m_pParent)->UpdateData(false);
// DestroyWindow();
}
}
Re: Parent to Child Dialog Data Transfer & Vise Versa in VC++
Usually such a "Data Transfer" is performed in following way:
- You implement in a child dialog all the data variables you need to be changed or/and displayed.
- You set all these data values in a child dialog just before calling its DoModal() from a parent window.
- After its DoModal returns IDOK you can set all the data values you need from the child dialog to the parent.
Re: Parent to Child Dialog Data Transfer & Vise Versa in VC++
hi
how can i set the values after return the DoModal == IDOK.
I did like bellow,
code wrote in child dlg,
CParent parObj;
if(parObj.DoModel() == IDOK)
{
child1ctrl.GetWindowText(parObj.parentval);
::AfxMessageBox(parObj.parentval); // Value transfer from child to parent
parObj.parentctrl.SetWindowText(child1val); //but error occur in this statement.
}
Now, a new duplicate parent window will shown and also transferred the child data.
but my requirement is,single modeless parent & child dialog. both are in open condition.
If i change the value in parent it will update in child & vies verse.
Pls clear me. I'm in basic level student in visual c++.
Re: Parent to Child Dialog Data Transfer & Vise Versa in VC++
After DoModal returns neiter a dilog window nor controls in it more exist. So you cannot access them anymore.
Instead you have to set all the data from the controls to the dialog data variables (strings, numbers, some class or struct objects and so on). You must do it before the dialog OnOk() method returns.
Then you'll be able to access this data from the parent after DoModal returns.
Re: Parent to Child Dialog Data Transfer & Vise Versa in VC++
Can you send any sample code....
Re: Parent to Child Dialog Data Transfer & Vise Versa in VC++
Do you know how to add data member variables in a dialog?
Did you ever read MSDN?
and here is some tutorial with a sample code:
http://aclacl.brinkster.net/MFC/ch08b.htm
PS: you could also yourself search with Google for what you need (modal dialog code sample mfc data exchange ... and so on)
Re: Parent to Child Dialog Data Transfer & Vise Versa in VC++
Quote:
Originally Posted by
saraswathisrinath
but my requirement is,single modeless parent & child dialog. both are in open condition.
If i change the value in parent it will update in child & vies verse.
So do you want a modal or modeless dialog? If the child dialog should be modeless, then why does it have OK and Cancel buttons? I think you should explain better what you want.
Also, why did you implement message handlers for the OK and Cancel buttons in CChildDlg? CDialog already has virtual functions OnOK and OnCancel that are called by the framework (also when the user presses the Enter or Esc key).
Re: Parent to Child Dialog Data Transfer & Vise Versa in VC++
Hi Victor,
Thanks for your valuable reply..
I searched the code in google & apply. but my requirment is not fulfil.
but i'm little poor in vc++. I know the basic level, how to add variable & method.
My doubt is, I'm using modeless dialog, if i used the below code means, one more dialog will open.
if (dlg.DoModal () == IDOK) {
CString strName = dlg.m_strName;
CString strPhone = dlg.m_strPhone;
TRACE (_T ("Name=%s, Phone=%s"), strName, strPhone);
}
My requirement is modelless parent with child dialog and also transfer the data between us.
Re: Parent to Child Dialog Data Transfer & Vise Versa in VC++
Hi D_Drmmr,
sorry for the late reply, I want modeless dialog.
sorry i wrote the function like send data from child dialog to parent dialog in the default CANCEL
button, and also didn't remove the OK button.
My Requirement:
***************************
I'm using MSComm control in my parent dialog for serial communication.
Using this, I send/received the data at every sec from my parent dialog.
now, I display the particular edit control value from parent to child dialog,
and also change the value from child's child screen to parent & child dialog.
Ex:
Parent ---------------------Child ------------> Modeless dialog
Current = 100 -----------Current = 100 -----------> It display the parent value only.
Child------------------------Child's child -----------> Model dialog
Current = 100------------Current = 100 -----------> If i change the child's child dialog, the value
must change in the parent dialog and the above condition the parent value shown in the
modeless child dialog. Child's child current value = 150, then parent & child current value = 150.