Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Working with two dialogs.

Posted on 2000-04-10
3
Medium Priority
?
243 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
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 300 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

972 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