How do I transfer data from child dialog to the parent Cformview?

Posted on 2004-10-29
Last Modified: 2013-11-20
I am new to MFC programming and I'm trying to transfer data (for example, which check boxes were checked or which radio button was selected) from a child dialog to the parent formview.  The formview needs to know what was selected in the child dialgo box.  I want to update a static text control or a editable text control in the formview, once the user has clicked on the "OK" button on the child dialog box.  I am using MFC document/view architecture and my application is a SDI.  Can someone provide me with some ideas on which is the best way for the parent formview be aware on what was selected in the child dialog?

Question by:urivera
    LVL 6

    Assisted Solution

    by:Amritpal Singh
    for transferring information in case of dialogs u use the technique known as Dialog Data Exchange (or DDX).
    u have to declare member function in ur data class ,that will correspond to each control .
    then u'll use DoDataExchange for actual transfer

    for an example have a look at the following link
    LVL 6

    Expert Comment

    by:Amritpal Singh
    LVL 48

    Accepted Solution

    Add public class members to the child class dialog:

    class CChildDialog
        int m_nRadioSelection;
        CString m_sText;

    Fill these members in OnOK:

    void CChildDialog::OnOK()
        m_nRadioSelection = ...;
        m_sText = ...;

    Get their values from the parent class:

    void CParent::OnShowChild()
        CChildDialog dlg(this);
        if ( dlg.DoModal == IDOK )
            // ise dlg.m_nRadioSelection and dlg.m_sText here

    Notice that m_nRadioSelection and m_sText should not be members linked to dialog controld using DDX. You may keep another class members for this, and use their values to set output data in OnOK.

    Author Comment

    Thanks for your replies

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
    Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Want to pick and choose which updates you receive? Feel free to check out this quick video on how to manage your email notifications.

    875 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now