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

HI,
     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 );
  return;
 }
 UpdateData();
 pParent->m_edit1.SetDlgItemTextW(IDC_EDIT1,m_editstr1);
 //Invalidate();
 pParent->m_edit1.Invalidate();
 

}

LVL 1
Amitg_kAsked:
Who is Participating?
 
js-profiCommented:
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

    pParent->m_edit1.SetWindowText(m_editstr2);

if that works make a member function in CproxeDlg for doing the update.
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
CprodexDlg* pParent = (CprodexDlg*)GetParent();
if(NULL != pParent)
{
  CString s;
  GetDlgItemText(IDC_EDIT1, s);
  pParent->SetDlgItemText(IDC_EDIT1, s);
  return;
}
ASSERT(FALSE);
}
0
 
AndyAinscowFreelance programmer / ConsultantCommented:
ps.  It is often best to explicitly set the parent eg.

CDlg2 dlg(this);
dlg.DoModal();
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.