How to update editbox data in the parent dialog in child dialog created by using do modal.

Posted on 2010-01-06
Last Modified: 2013-12-14
     I am working on VC++(MFC) dialog based application. I have an editbox  in the first dialog(say dialog1). in the dialog1 there is a button, on button click event, I am launching dialog2 by using do modal (or modelless also). In the dialog2 i have another editbox, how can I update Edit1 as edit2 changes.

I have written following code in on editchange of editbox in the dlg2
void dlg2::OnEnChangeEdit1()
    //CprodexDlg *pdlg1 = (CprodexDlg*)GetParent();

 CWnd* pWnd = GetParent();
 CprodexDlg* pParent = STATIC_DOWNCAST( CprodexDlg, pWnd );
 if ( NULL == pParent )
  ASSERT( 0 );


Question by:Amitg_k
    LVL 43

    Expert Comment

    CprodexDlg* pParent = (CprodexDlg*)GetParent();
    if(NULL != pParent)
      CString s;
      GetDlgItemText(IDC_EDIT1, s);
      pParent->SetDlgItemText(IDC_EDIT1, s);
    LVL 7

    Accepted Solution

    the SetDlgItemTextW is the wrong function. it would look for IDC_EDIT1 in the dialog2. and you have to get the value from edit 2. try


    if that works make a member function in CproxeDlg for doing the update.
    LVL 43

    Expert Comment

    ps.  It is often best to explicitly set the parent eg.

    CDlg2 dlg(this);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Suggested Solutions

    Title # Comments Views Activity
    L prefix in C++ 8 89
    Implementing a ResolveEventHandler in C++ 13 97
    Pointers - Drive letter 1 58
    Eclipse XML hightlightning 5 34
    Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
    How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from ( Go to that link and select download selenium in the right hand columnThat will then direct you to their downlo…
    The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    737 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

    20 Experts available now in Live!

    Get 1:1 Help Now