Solved

Working with two dialogs.

Posted on 2000-04-10
3
233 Views
Last Modified: 2013-11-20
Hallo,

I have two dialogs. Lets call them Dialog1 and Dialog2.
The main dialog is Dialog1, and Dialog2 pops up when I click somewhere
in Dialog1.
In Dialog2 I have a Combobox, and I get the problem (Assertion Failure) when
I try to retrieve the information of this combobox from Dialog1, with a sentence
like this:
      int PMODEPADsel = dlg.m_CDecTypeOfTheNewSC.GetCurSel();
//m_CDecTypeOfTheNewSC is the variable associated to the combobox.

Well, the whole code of this part is:

if(dlg.DoModal() == IDOK)
{
      if (dlg.m_NameOfTheNewSC!=""){
            SetAllRelatedToSC(true);
            ActualEnsemble->ListOfSC[num].SC_Label=dlg.m_NameOfTheNewSC;
            ActualEnsemble->ListOfSC[num].String1=dlg.m_CDecChAdrOfTheNewSC;
            ActualEnsemble->ListOfSC[num].String2=dlg.m_CDecChIdOfTheNewSC;
//Here is where I get the problem!!:
            int PMODEPADsel = dlg.m_CDecTypeOfTheNewSC.GetCurSel();
            if (PMODEPADsel==0){  //PAD selected
                  m_PMODEPAD.SetCurSel(0);
            }
            if (PMODEPADsel==1){  //PMODE selected
                  m_PMODEPAD.SetCurSel(1);
            }
      }
}
0
Comment
Question by:javigil1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Expert Comment

by:paulburns
ID: 2702457
You can't use any member functions of  control's once the dialog has been dismissed. All those controls in the dialog have been destroyed at that point and although you may still have a CComboBox object around its no longer attached to an *actual* combo box.

Use DDX to save the user's selection from the combo to a member variable.
0
 
LVL 1

Accepted Solution

by:
jianliuer earned 75 total points
ID: 2702720
When the modal dialog is closed(click the OK button),all controls in the dialog are destroyed(the combobox is destroyed).So you should save the selection state in the virtual function CDialog::OnOK();

You can do like this:

m_PMODEPADsel is a member variable of your CXXXDialog class.

CXXXDialog::OnOK()
{
 UpdateData();
 m_PMODEPADsel =  m_CDecTypeOfTheNewSC.GetCurSel();
//////////////////////
 CDialog::OnOK();
}


if(dlg.DoModal() == IDOK)
{
if (dlg.m_NameOfTheNewSC!=""){
SetAllRelatedToSC(true);
ActualEnsemble->ListOfSC[num].SC_Label=dlg.m_NameOfTheNewSC;
ActualEnsemble->ListOfSC[num].String1=dlg.m_CDecChAdrOfTheNewSC;
ActualEnsemble->ListOfSC[num].String2=dlg.m_CDecChIdOfTheNewSC;

//Here it is!
int PMODEPADsel = dlg.m_PMODEPADsel;

if (PMODEPADsel==0){  //PAD selected
m_PMODEPAD.SetCurSel(0);
}
if (PMODEPADsel==1){  //PMODE selected
m_PMODEPAD.SetCurSel(1);
}
}
}
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2703500
What you can do is that you can have an array/list member in dialog1 for storing all the items in the combobox and an integer to store the current selection.
Fill up the array/list in Dialog2 with the items in the combobox and set the current selection. Now when the 2nd dialog is closed, you can still access the selected position and the item in that position.
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

734 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