[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2010-01-06
3
Medium Priority
?
578 Views
Last Modified: 2013-12-14
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();
 

}

0
Comment
Question by:Amitg_k
  • 2
3 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 26197689
CprodexDlg* pParent = (CprodexDlg*)GetParent();
if(NULL != pParent)
{
  CString s;
  GetDlgItemText(IDC_EDIT1, s);
  pParent->SetDlgItemText(IDC_EDIT1, s);
  return;
}
ASSERT(FALSE);
}
0
 
LVL 7

Accepted Solution

by:
js-profi earned 500 total points
ID: 26197692
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
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 26197695
ps.  It is often best to explicitly set the parent eg.

CDlg2 dlg(this);
dlg.DoModal();
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

830 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