Parent to Child Dialog Data Transfer & Vise Versa in VC++
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Parent to Child Dialog Data Transfer & Vise Versa in VC++

  1. #1
    Join Date
    Nov 2011
    Location
    India
    Posts
    128

    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();

    }

    }
    Attached Files Attached Files
    Regards,

    SaraswathiSrinath

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,003

    Re: Parent to Child Dialog Data Transfer & Vise Versa in VC++

    Usually such a "Data Transfer" is performed in following way:
    1. You implement ain a child dialog all the data variables you need to be changed or/and displayed.
    2. You set all these data values in a child dialog just before calling its DoModal() from a parent window.
    3. After its DoModal returns IDOK you can set all the data vaules you need from the child dialog to the parent.
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2011
    Location
    India
    Posts
    128

    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++.
    Last edited by saraswathisrinath; November 29th, 2012 at 03:51 AM.
    Regards,

    SaraswathiSrinath

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,003

    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.
    Victor Nijegorodov

  5. #5
    Join Date
    Nov 2011
    Location
    India
    Posts
    128

    Re: Parent to Child Dialog Data Transfer & Vise Versa in VC++

    Can you send any sample code....
    Regards,

    SaraswathiSrinath

  6. #6
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,003

    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)
    Victor Nijegorodov

  7. #7
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    1,998

    Re: Parent to Child Dialog Data Transfer & Vise Versa in VC++

    Quote Originally Posted by saraswathisrinath View Post
    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).
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  8. #8
    Join Date
    Nov 2011
    Location
    India
    Posts
    128

    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.
    Last edited by saraswathisrinath; December 1st, 2012 at 04:57 AM.
    Regards,

    SaraswathiSrinath

  9. #9
    Join Date
    Nov 2011
    Location
    India
    Posts
    128

    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.
    Last edited by saraswathisrinath; December 2nd, 2012 at 10:04 PM.
    Regards,

    SaraswathiSrinath

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center