• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 248
  • Last Modified:

Working with two dialogs.

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
javigil1
Asked:
javigil1
1 Solution
 
paulburnsCommented:
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
 
jianliuerCommented:
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
 
V_BapatCommented:
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
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.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now